Изменение размера кнопки изображения - PullRequest
0 голосов
/ 10 апреля 2019

Я настраиваю кнопку изображения в 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);


    }

}

Предварительный просмотр

Есть ли у кого-нибудь какие-либо советы по исправлению этого?

Ответы [ 2 ]

0 голосов
/ 10 апреля 2019

Попробуйте добавить layout_constraintHorizontal_bias и layout_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>
0 голосов
/ 10 апреля 2019

Удалите поля (начало, верх, низ, конец) и настройте layout_constraintHorizontal_bias, layout_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" />
...