【问题标题】:Adjust items height to fit its RecyclerView according to screen size根据屏幕大小调整项目高度以适合其 RecyclerView
【发布时间】:2018-09-16 12:53:30
【问题描述】:

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

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

问题:

预期:

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

【问题讨论】:

  • 将布局高度改为0dp
  • 如果你这样做,请记住没有观点会被回收,因此拥有 recylerview 毫无意义。

标签: java android xml android-layout


【解决方案1】:

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

More about flexible layouts.

An example illustrating the use of flexible layouts.

【讨论】:

  • 添加链接很有帮助,但多写几行同样的内容会更有帮助。
  • 试过了,对我的recyclerView没有任何影响。
猜你喜欢
  • 1970-01-01
  • 2015-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-09
  • 2017-12-15
  • 2017-01-19
相关资源
最近更新 更多