#android
Вопрос:
Я пытаюсь создать форму для отправки сообщений, и мне нужно, чтобы заголовок и адрес электронной почты получателя находились в верхней части, в середине, занимающей большую часть экрана, этот редактируемый et_mensaje
текст, а в нижней части экрана находится кнопка «Отправить«, но в моем xml-файле кнопка выходит за рамки. Я не хочу размещать значения на высотах et_mensaje
, я хочу, чтобы они автоматически подстраивались под разные экраны
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="20dp"
>
<TextView
android:id="@ id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/NEGRO"
android:text="Message Demo"
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
android:id="@ id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_below="@id/text1"
android:orientation="horizontal">
<TextView
android:id="@ id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/LinearLayout1"
android:textColor="@color/NEGRO"
android:layout_weight="1"
android:textSize="16sp"
android:text="Para: " />
<EditText
android:id="@ id/et_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="9"
android:inputType="textEmailAddress"
android:textSize="16sp"
/>
</LinearLayout>
<TextView
android:id="@ id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/NEGRO"
android:layout_below="@id/LinearLayout1"
android:layout_marginTop="20dp"
android:textSize="16sp"
android:text="Mensaje:" />
<EditText
android:id="@ id/et_mensaje"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/NEGRO"
android:layout_below="@id/textView3"
android:layout_weight="1"
android:textSize="16sp"
android:background="@drawable/edittext_bg"
android:inputType="textPersonName"
/>
<Button
android:id="@ id/bt_SendButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/et_mensaje"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:text="ENVIAR MAIL" />
Ответ №1:
Если все, что вам нужно, не помещается на экране, вы можете использовать ScrollView, чтобы прокрутить его до нижней части экрана. Поскольку ваш родительский макет является линейным, вы можете использовать кнопку «Отправить» в самом конце, как и сейчас.
Если вы хотите, чтобы все было на экране (без использования ScrollView), вы можете установить вес для каждого компонента.
(Кроме того, я не думаю, что вам понадобится самый внешний (родительский) LinearLayout; похоже, вы используете RelativeLayout.)
Ответ №2:
Вам нужно удалить android:layout_below="@id/et_mensaje"
из Button
и добавить android:layout_above="@ id/bt_SendButton"
в EditText
Ответ №3:
вы можете использовать вес, чтобы сделать его лучше, вместо того, чтобы давать значения
подобный этому
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:orientation="vertical"
android:layout_gravity="center">
<EditText
android:id="@ id/et_mensaje"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textColor="@color/NEGRO"
android:layout_below="@id/textView3"
android:layout_weight="1"
android:textSize="16sp"
android:background="@drawable/edittext_bg"
android:inputType="textPersonName"
/>
<Button
android:id="@ id/bt_SendButton"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_below="@id/et_mensaje"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:text="ENVIAR MAIL" />
и добавьте другой элемент, как вы хотите, но не забудьте указать 0dp