代码之家  ›  专栏  ›  技术社区  ›  Quillion

相对布局中的滚动视图

  •  -1
  • Quillion  · 技术社区  · 7 年前

    我有一个巨大的项目列表,我将其放入线性布局,然后将其放入scrollview以使其可滚动。

    然后我将其全部打包到相对视图中,因为我希望在底部有“添加”按钮。

    <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="match_parent"
            android:layout_width="match_parent">
        <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">
    
    A LOT OF CONTENT
    
    
            </LinearLayout>
        </ScrollView>
    
        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:id="@+id/add"
                android:text="@string/add"
                android:paddingTop="23dp"/>
    </RelativeLayout>
    

    由于每当我滚动到列表的最底部时,添加按钮都位于底部,因此添加按钮会阻止滚动视图最底部的部分。如何使scrollview只适合添加按钮不占用的屏幕部分?

    2 回复  |  直到 7 年前
        1
  •  1
  •   ADM    7 年前

    设置规则 android:layout_above="@+id/add" ScrollView

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_above="@+id/add"
            android:layout_height="match_parent">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                A LOT OF CONTENT
    
    
            </LinearLayout>
        </ScrollView>
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:id="@+id/add"
            android:text="@string/add"
            android:paddingTop="23dp"/>
    </RelativeLayout>
    
        2
  •  1
  •   Peter Stewart    7 年前

    将此添加到滚动视图:

     android:layout_above="@+id/add"