根据屏幕尺寸调整项的高度以适应其RecyclerView

8

我有一个高度为match_parent的RecyclerView,在适配器中显示16个具有固定高度的垂直项。除了涉及不同屏幕尺寸时,一切运作良好。在较大的屏幕上,16个项目显示后底部会保留一些空间,而在小屏手机上,则完全适合底部。我正在寻找一种方式,可以使列表项的高度根据RecyclerView高度调整到末尾且不能滚动。

查看下面的屏幕截图以获得更多澄清:

问题:

enter image description here

期望:

enter image description here

我的方法是将项目重量设置为1,因此当渲染16次进入RecyclerView时,它们将在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" />

我的适配器:

<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>

1
将布局的高度更改为0dp。 - anzaidemirzoi
如果你正在做这个,请记住没有视图会被回收,因此拥有一个可回收视图是毫无意义的。 - humblerookie
1个回答

2

添加链接是有帮助的,但写几行关于同样主题的内容会更加有益。 - Sivaprasanna Sethuraman
我尝试了,但它对我的recyclerView没有任何影响。 - VipiN Negi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接