Изменение размера формы в Android в зависимости от размера устройства - PullRequest
0 голосов
/ 26 сентября 2019

Я сделал эту форму, которая на моем эмуляторе (Google Pixel c) выглядит следующим образом:

enter image description here

Затем я попробовалприложение на Samsung Galaxy Tab и появилась белая полоса:

enter image description here

Как это исправить?Это мой xml-код вида:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/MyDialog"
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"
android:gravity="center">

<Button
    android:id="@+id/button_form"
    android:layout_width="@dimen/_20sdp"
    android:layout_height="@dimen/_10sdp"
    android:layout_below="@+id/nameEditText"
    android:layout_marginLeft="@dimen/_30sdp"
    android:layout_marginTop="@dimen/_5sdp"
    android:layout_marginBottom="@dimen/_7sdp"
    android:background="@drawable/button_bg"
    android:textAlignment="center"
    android:textColor="@color/whiteTextColor"
    android:textSize="@dimen/_7sdp"
    android:text="OK">

</Button>

<CheckBox
    android:id="@+id/myCheckBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="@dimen/_11sdp"
    android:text="Abilitare la palette di colori?" />

<EditText
    android:id="@+id/nameEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/genderRadioGroup"
    android:layout_alignParentLeft="true"
    android:layout_marginTop="@dimen/_2sdp"
    android:ems="10"
    android:hint="Inserisci l'eta'">

    <requestFocus />
</EditText>

<RadioGroup
    android:id="@+id/genderRadioGroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/myCheckBox">


    <RadioButton
        android:id="@+id/maleRadioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="@dimen/_3sdp"
        android:text="Maschio" />


    <RadioButton
        android:id="@+id/femaleRadioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/maleRadioButton"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="@dimen/_1sdp"
        android:text="Femmina" />
</RadioGroup>

Я использовал библиотеку SDP, чтобы адаптировать ее к любому разрешению экрана.Может ли это быть проблемой?

1 Ответ

0 голосов
/ 27 сентября 2019

Решено в соответствии с предложением @ vidulaJ

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/MyDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">

<Button
    android:id="@+id/button_form"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/nameEditText"
    android:layout_marginLeft="@dimen/_24sdp"
    android:layout_marginTop="@dimen/_5sdp"
    android:layout_marginBottom="@dimen/_7sdp"
    android:background="@drawable/button_bg"
    android:textAlignment="center"
    android:textColor="@color/whiteTextColor"
    android:textSize="@dimen/_7sdp"
    android:text="OK">

</Button>

<CheckBox
    android:id="@+id/myCheckBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="@dimen/_11sdp"
    android:text="Abilitare la palette di colori?" />

<EditText
    android:id="@+id/nameEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/genderRadioGroup"
    android:layout_alignParentLeft="true"
    android:layout_marginTop="@dimen/_2sdp"
    android:ems="10"
    android:hint="Inserisci l'eta'">

    <requestFocus />
</EditText>

<RadioGroup
    android:id="@+id/genderRadioGroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/myCheckBox">


    <RadioButton
        android:id="@+id/maleRadioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="@dimen/_3sdp"
        android:text="Maschio" />


    <RadioButton
        android:id="@+id/femaleRadioButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/maleRadioButton"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="@dimen/_1sdp"
        android:text="Femmina" />
</RadioGroup>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...