如何在布局中显示顶部和底部视图为常量-android



我有一个布局,有一个顶部视图、底部视图和滚动视图。

滚动视图包含编辑文本。当编辑文本获得焦点时,底部视图也会向上滚动。如何避免这种情况。

我已经尝试在清单文件android:windowSoftInputMode作为

adjustResize
adjustPan

但仍然是btm布局滚动,或者顶部布局上移。

我的样本布局是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <View
        android:id="@+id/topView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:background="#123456" />
    <View
        android:id="@+id/btmView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="#123456" />
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <View
                android:layout_width="match_parent"
                android:layout_height="300dp"
                 />
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content" 
                android:layout_marginBottom="50dp"/>
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

我希望顶部布局和底部布局必须是常量。如何做到这一点?

使用

   android:layout_below="@+id/topView"
   android:layout_above="@+id/btmView"

像这个一样在滚动视图中

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
        <View
            android:id="@+id/topView"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:background="#123456" />
        <View
            android:id="@+id/btmView"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:background="#123456" />
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
             android:layout_below="@+id/topView"
            android:layout_above="@+id/btmView"
           >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1000dp"
                     />
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" 
                    android:layout_marginBottom="50dp"/>
            </LinearLayout>
        </ScrollView>
    </RelativeLayout>

最新更新