【发布时间】:2020-08-24 06:04:08
【问题描述】:
我正在尝试设置一个布局,其中一个“X”按钮固定在屏幕顶部,然后两个元素在视图中居中。一个是回收器视图,然后固定在回收器视图下方,一个用于提交表单的按钮。我目前一直在使用的布局,直到回收站视图超出其界限。然后提交按钮被推到视图边界以下,回收器视图不会停留在布局内。如果回收器视图变大,如何使两个回收器和按钮视图居中但不让按钮超出视图边界?
使用 Small Recycler View 的视图显示为(它应该居中。我的示例稍微偏离了。)
更大的 Recycler View 应该如何显示(recycler 视图的内容太大而无法滚动)
View 如何在更大的 Recycler View 中实际显示(recycler 视图会滚动,但现在它将按钮从视图底部推开,显示为按钮被切断)
XML 布局的相关代码块
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.45"
android:orientation="vertical"
android:background="@color/backgroundLightSecondary"
android:padding="20dp" >
<Button
android:id="@+id/bt_close"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:background="@drawable/ic_close"
android:textColor="@color/textLightPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center_vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_item_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/bt_order"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_weight="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="@drawable/bt_rounded_corner"
android:fontFamily="@font/microbrew_two"
android:padding="3dp"
android:text="@string/btn_add_to_order"
android:textColor="@color/backgroundLightSecondary"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
将按钮固定在中间,使其不会被按下。
标签: android xml android-layout android-recyclerview