如何使布局保持在软键盘的顶部

时间:2012-11-28 11:59:06

标签: android layout android-softkeyboard

我有一个应用程序,其中包含一个带有textview的布局。现在,使用android时会发生什么:windowSoftInputMode =“adjustPan”是指键盘打开时整个屏幕都会亮起。但观点减少了一半。那是没有键盘的图像: enter image description here

打开键盘的那些: enter image description here

如您所见,文本框已被删除。我希望它像facebook一样: 键盘关闭: enter image description here

键盘打开: enter image description here

我该如何管理?在Facebook中,整个布局都在键盘上方。 谢谢!

1 个答案:

答案 0 :(得分:0)

使用相对布局作为根布局并使用

  

机器人:layout_alignParentBottom = “真”

到您的子视图,使其使用软键盘向上滑动

以下是示例代码。

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/background_light">
    <Button
        android:text="Add Contact"
        android:id="@+id/addContact"
        android:layout_alignParentTop="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"></Button>

    <EditText
        android:id="@+id/searchEditText"
        android:layout_below="@id/addContact"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:hint="Search" />
    <ExpandableListView
        android:layout_below="@id/searchEditText"
        android:layout_above="@+id/selection_layout"
        android:id="@+id/contactList"
        android:layout_width="fill_parent"
        android:layout_height="0px"
        ></ExpandableListView>
    <LinearLayout
        android:id="@+id/selection_layout"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:gravity="center"
        android:background="@drawable/black_white_gradient"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:id="@+id/ok"
            android:text="Ok" />
        <Button
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:id="@+id/cancel"
            android:text="Cancel" />
    </LinearLayout>
</RelativeLayout>
相关问题