图像按钮调整大小

Image Button resizing

我正在 Android Studio 中设置图像按钮。在设计视图中一切看起来都很好,但是当应用程序加载时,图像按钮被移动到左上角并且尺寸变小了?

如下所示:

设计视图

XML代码-当前



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.PhysicalActivity">

    <ImageButton
        android:id="@+id/btnImageGallery"
        android:layout_width="200dp"
        android:layout_height="300dp"
        android:layout_marginStart="8dp"
        android:onClick="onImageGalleryClicked"
        android:src="@drawable/placeholder"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.921"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.74" />
</android.support.constraint.ConstraintLayout>

体力活动代码

package com.example.futura.ui;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.example.futura.R;

import java.io.File;

public class PhysicalActivity extends AppCompatActivity {

    public static final int IMAGE_GALLERY_REQUEST = 20;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_physical1);

    }

    public void onImageGalleryClicked(View v){


        // invoke the image gallery using an implict intent.
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);

        File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        String pictureDirectoryPath = pictureDirectory.getPath();

        // finally, get ui represenation

        Uri data = Uri.parse(pictureDirectoryPath);

        // set the data and type, get all image types

        photoPickerIntent.setDataAndType(data, "image/*" );

        startActivityForResult(photoPickerIntent, IMAGE_GALLERY_REQUEST);


    }

}

预览

有人对纠正这个问题有什么建议吗?

删除边距(开始、顶部、底部、结束)并调整 layout_constraintHorizontal_biaslayout_constraintVertical_bias 以获得所需的结果。

<android.support.v7.widget.AppCompatImageButton
    android:id="@+id/startSyncButton"
    android:layout_width="200dp"
    android:layout_height="300dp"
    app:layout_constraintHorizontal_bias="0.9"
    app:layout_constraintVertical_bias="0.7"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

尝试添加 layout_constraintHorizontal_biaslayout_constraintStart_toStartOf

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageButton
        android:id="@+id/btnImageGallery"
        android:layout_width="200dp"
        android:layout_height="300dp"
        android:layout_marginStart="8dp"
        android:onClick="onImageGalleryClicked"
        android:src="@drawable/placeholder"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.921"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.74" />
</android.support.constraint.ConstraintLayout>