软键盘上方的特殊布局

时间:2017-12-07 07:58:34

标签: android android-layout android-xml android-softkeyboard

我有一个布局,代码如下

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <EditText
        android:id="@+id/et_question"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/white" />

    <LinearLayout
        android:id="@+id/ll_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!--some stuff here-->

    </LineaLayout>

    <LinearLayout
        android:id="@+id/ll_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!--some stuff here-->

    </LineaLayout>

</LinearLayout>

在上面的布局中,当键盘可见时,我希望布局ll_1超越软键盘,但布局ll_2不应该。

1 个答案:

答案 0 :(得分:0)

您可以尝试Relativelayout代替Linearlayout吗? 像这样。

<Relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!--If it is at the top. If not, delete the alignParentTop feature.-->
    <EditText
        android:id="@+id/et_question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" 
        android:background="@color/white" />

    <RelativeLayout
        android:id="@+id/ll_1"
        android:layout_width="match_parent"
        android:layout_below="@+id/et_question"
        android:layout_height="wrap_content">

        <!--some stuff here-->

    </RelativeLayout>

    <!--If it is at the top. If not,delete the alignParentBottom feature.-->
    <RelativeLayout
        android:id="@+id/ll_2"
        android:layout_width="match_parent"
        android:layout_below="@+id/ll_1"
        android:layout_alignParentBottom="true"
        android:layout_height="wrap_content">

        <!--some stuff here-->

    </RelativeLayout>

</Relativelayout>

如果您不介意,请首先尝试在android:layout_alignParentBottom="true"上使用ll_2