【发布时间】:2021-08-29 10:31:32
【问题描述】:
快速背景:我的部分活动处于相对布局中。我是故意这样做的,因为我想要一个直接位于列表视图下方的按钮。我希望按钮在列表视图展开时向下移动,这就是我以这种方式设置它的原因。我已经设置了列表视图的高度来包裹内容,这样在相对布局中,按钮会随着列表的展开而向下移动。
问题:一旦列表变得足够大以至于内容填满屏幕,按钮仍保留在列表下方(这很好)但我无法向下滚动列表以显示按钮。列表下方的按钮“消失”。我怎样才能做到这一点,以便我可以在列表/屏幕上滚动以显示我的按钮?
编辑:我确实希望按钮离开屏幕,我只是希望能够向下滚动以再次看到它。
下面的示例代码 + 图片: 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>
【问题讨论】:
-
您可以使用 LinearLayout 或 ConstraintLayout 来执行此操作。RelativeLayout 存在性能问题
-
哦,在这种情况下,相对布局是线性布局的子布局
标签: android android-layout listview android-listview