[英]Adjust items height to fit its RecyclerView according to screen size
I have a RecyclerView
with height:match_parent which displays 16 items vertically with fixed height in adapter. 我有一个带有height:match_parent的
RecyclerView
,它在适配器中以固定的高度垂直显示16个项目。 Everything works fine except when it comes to the different screen sizes. 一切工作正常,除非涉及到不同的屏幕尺寸。 In larger screens there is a space remained at the bottom after 16 items are displayed, where on small screen phones it perfectly fits to the bottom.
在大屏幕中,显示16个项目后,底部会保留一个空间,在小屏幕手机上,该位置正好适合底部。 I am looking for a way where list items heights are adjusted to the
RecyclerView
height till the end without scrollable. 我正在寻找一种方法,将列表项的高度调整到
RecyclerView
高度,直到最后没有滚动。
Check the Screenshots below for more clarification 查看下面的屏幕截图以获取更多说明
Problem: 问题:
Expectation: 期望:
My approach was to make the Item weight set to 1, hence when rendering into the RecyclerView
16 times, they will share the same height within the RecyclerView
. 我的方法是将Item的权重设置为1,因此当渲染到
RecyclerView
16次时,它们将在RecyclerView
共享相同的高度。 Unfortunately that didn't work for me. 不幸的是,这对我没有用。
My RecyclerView: 我的RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_morning"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never" />
My Adapter: 我的适配器:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/white"
android:clickable="false"
android:orientation="vertical">
<TextView />
</LinearLayout>
The exact solution for your problem is the flexible layout manager for ReyclerView. 针对您的问题的确切解决方案是ReyclerView的灵活布局管理器。
More about flexible layouts. 有关灵活布局的更多信息。
An example illustrating the use of flexible layouts. 一个示例说明灵活布局的使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.