我有一个对话框片段,其中包含线性布局,其中涉及RecyclerView上方的titleText,在最底部,recyclerView下方有一个按钮.
由于recyclerView根据适配器设置的项目数展开或折叠,因此按钮有时会被截断并且不再显示在屏幕上,因为recyclerView仅覆盖整个屏幕.
我的问题是,有没有一种方法可以设置recyclerView的最大高度,而无需隐藏下面的按钮.我也不想只是给视图一个随机的高度,以防万一recyclerView不包含任何项目,而这只是一个空白部分.
如果您遇到过此问题,以及如何解决此问题,请告诉我.谢谢!
解决方法:
更新
您可以使用布局权重轻松实现此目的.这是一个例子:
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Title"
android:textSize="21sp"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="30dp">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Submit"/>
Title和RecyclerView将根据内容包装内容,而按钮将始终占据底部.
标签:android-recyclerview,android-layout,android
来源: https://codeday.me/bug/20191026/1938097.html