Возврат каретки в кнопках путает с полем - PullRequest
0 голосов
/ 14 марта 2019

Если я добавляю возврат каретки в кнопку, в верхней части появляется дополнительный бит "margin" (из-за отсутствия лучшего объяснения):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff992a2a">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="200dp">
        <Button
            android:layout_width="250dp"
            android:layout_height="100dp"
            android:text="Extend" />
        <Button
            android:layout_width="250dp"
            android:layout_height="100dp"
            android:text="Accept
0:23"/>
    </LinearLayout>
</RelativeLayout>

enter image description here

Если я не добавлю возврат каретки, он идеально выровняется: enter image description here

как я могу остановить появление дополнительного «поля»?Я попытался установить android:lines="2" и и / или android:singleline="false", но ничего не помогло.

Ответы [ 2 ]

1 голос
/ 14 марта 2019

Вам необходимо установить android:gravity="center" в вашем LinearLayout

КОД ОБРАЗЦА

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff992a2a">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:gravity="center"
        android:orientation="horizontal">

        <Button
            android:layout_width="250dp"
            android:layout_height="100dp"
            android:text="Extend" />

        <Button
            android:layout_width="250dp"
            android:layout_height="100dp"
            android:text="Accept
0:23" />
    </LinearLayout>
</RelativeLayout>
0 голосов
/ 14 марта 2019

Не нужно добавлять LinearLayout. Вы можете использовать только RelativeLayout. Попробуйте это

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff992a2a">

    <Button
        android:id="@+id/button_1"
        android:layout_width="250dp"
        android:layout_height="100dp"
        android:text="Extend" />

    <Button
        android:id="@+id/button_2"
        android:layout_width="250dp"
        android:layout_height="100dp"
        android:layout_toRightOf="@id/button_1"
        android:text="Accept
            0:23" />

</RelativeLayout>
...