欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

android 设置view最大高度,android-在RecyclerView上设置最大高度

发布时间:2023/12/10 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 android 设置view最大高度,android-在RecyclerView上设置最大高度 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我有一个对话框片段,其中包含线性布局,其中涉及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

总结

以上是生活随笔为你收集整理的android 设置view最大高度,android-在RecyclerView上设置最大高度的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。