根据屏幕尺寸调整项目高度以适合其RecyclerView

时间:2018-04-06 13:17:28

标签: java android xml android-layout

我有一个RecyclerView高度:match_parent,在适配器中垂直显示16个项目,固定高度。一切正常,除了不同的屏幕尺寸。在较大的屏幕中,在显示16个项目后底部留有空间,在小屏幕手机上它完全适合底部。我正在寻找一种方法,将列表项高度调整到RecyclerView高度直到结束而不滚动。

查看下面的屏幕截图以获得更多说明

问题:

enter image description here

期望:

enter image description here

我的方法是将Item权重设置为1,因此当渲染到RecyclerView 16次时,它们将在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 个答案:

答案 0 :(得分:0)

您的问题的确切解决方案是ReyclerView的灵活布局管理器。

More about flexible layouts.

An example illustrating the use of flexible layouts.

相关问题