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

How do I keep a button on screen which is below a listview when there are too many items in the list?

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

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

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

下面的示例代码 + 图片: 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>

<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>

用 ScrollView 包裹你的 ListView:

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

    <ScrollView
        android:id="@+id/scrollView"
        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" />
        
    </ScrollView>
    
    <Button
        android:id="@+id/logExerciseButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/scrollView"
        android:text="@string/log_set" />

</RelativeLayout>

将按钮作为页脚添加到列表视图会产生所需的行为:https://www.tutorialspoint.com/how-to-add-footer-in-android-listview