панель подгонки андроида к низу - PullRequest
0 голосов
/ 11 ноября 2011

У меня есть две кнопки в моей форме, сохранить и отменить.Когда я иду в форму, клавиатура показывает автоматически.(Кстати, форма имеет один EditText).Я действительно не знаю, как разместить кнопки снизу.Теперь кнопки расположены под EditText, я хочу поставить их над клавиатурой.

Для тех, кто хочет увидеть код:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView01" android:layout_width="fill_parent" 
        android:layout_height="fill_parent">

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" style="@style/Form">

        <LinearLayout android:id="@+id/linearLayout1" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent"
        android:layout_margin="7dp"
        android:orientation="vertical">

            <EditText 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:id="@+id/etNewListNameForm" 
                android:hint="list name"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"></EditText>

        </LinearLayout>

        <LinearLayout style="@style/BottomPanel"
            android:id="@+id/linearLayout2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <Button
                android:id="@+id/btnSaveCardList" 
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginTop="5dp"
                android:text="Save"></Button>
            <Button
                android:id="@+id/btnCancelCardLst" 
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="1"
                android:text="Cancel"></Button>

        </LinearLayout>

    </LinearLayout>
</ScrollView>

С наилучшими пожеланиями

Изображения: enter image description here enter image description here

Ответы [ 4 ]

2 голосов
/ 12 ноября 2011

Один из вариантов, который у вас есть, это использовать относительный макет вместо линейного и использовать атрибут alignParentBottom, например:

    <RelativeLayout android:id="@+id/linearLayout1" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:layout_margin="7dp"
    android:orientation="vertical">

        <EditText 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:id="@+id/etNewListNameForm" 
            android:hint="list name"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp"></EditText>

    </LinearLayout>

    <LinearLayout style="@style/BottomPanel"
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true">
        .....

Редактировать: Стоит также отметить, что вы должны очень серьезно рассмотреть возможность использования более описательногоимена для ваших взглядов.Вы использовали описательные имена для ваших кнопок и EditTexts, но застряли с linearLayout1 и linearLayout2 для ваших видов компоновки.Подумайте над тем, чтобы назвать их как mainLayout, bottomPannelLayout или как-то еще, и вам будет легче в будущем, когда вы попытаетесь выяснить, как вы их настроили.

0 голосов
/ 12 ноября 2011

Удалите ненужные представления и используйте относительныйLayuot

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="#ff0022">


    <LinearLayout android:id="@+id/linearLayout2"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <Button android:layout_marginTop="5dp" android:text="Save"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_weight="1" android:id="@+id/btnSaveCardList"></Button>
        <Button android:layout_marginTop="5dp" android:text="Cancel"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_weight="1" android:id="@+id/btnCancelCardLst"></Button>

    </LinearLayout>
    <EditText android:layout_height="wrap_content"
        android:layout_margin="7dp" android:hint="list name"
        android:layout_width="fill_parent" android:id="@+id/etNewListNameForm"
        android:layout_alignParentTop="true" android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp">
        <requestFocus></requestFocus>
    </EditText>
</RelativeLayout>
0 голосов
/ 12 ноября 2011
  1. Оберните ваш ScrollView в RelativeLayout,
  2. переместите LinearLayout с помощью кнопок, чтобы стать вторым дочерним элементом этого RelativeLayout,
  3. и установите для android: layout_alignParentBottom значение true для этого LinearLayout.
0 голосов
/ 11 ноября 2011

В LinearLayout, содержащем ваш EditText, измените android:layout_height на 0dp и установите android:layout_weight на 1.Таким образом, он займет все остальное пространство в родительском элементе после того, как панель кнопок займет свою долю.

...
    <LinearLayout android:id="@+id/linearLayout1" 
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_margin="7dp"
        android:orientation="vertical">

        <EditText 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:id="@+id/etNewListNameForm" 
            android:hint="list name"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp"></EditText>

    </LinearLayout>
...
...