首页 > 解决方案 > 当列表中有太多项目时,如何在列表视图下方的屏幕上保留一个按钮?

问题描述

快速背景:我在相对布局中有一部分活动。我是故意这样做的,因为我想要一个直接位于列表视图下方的按钮。我希望按钮在列表视图展开时向下移动,这就是我以这种方式设置它的原因。我已经设置了列表视图的高度来包装内容,这样在相对布局中,按钮会随着列表的展开而向下移动。

问题:一旦列表变得足够大以至于内容填满屏幕,按钮仍保留在列表下方(这很好),但我无法向下滚动列表以显示按钮。列表下方的按钮“消失”。我怎样才能做到这一点,以便我可以在列表/屏幕上滚动以显示我的按钮?

编辑:我确实希望按钮离开屏幕,我只想能够向下滚动以再次查看它。

下面的示例代码+图像:3张图片,一张显示初始布局,接下来你可以看到按钮随着我的列表展开而移动,第三,最终按钮到达底部,我无法滚动更多来点击它。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ListView
        android:id="@+id/workoutList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/logExerciseButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/workoutList"
        android:text="@string/log_set" />

</RelativeLayout>

初始设置

移动按钮

按钮消失无法滚动

标签: androidandroid-layoutlistviewandroid-listview

解决方案


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/workoutList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/logExerciseButton" />

    <Button
        android:id="@+id/logExerciseButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/log_set" />

</RelativeLayout>

推荐阅读