簡體   English   中英

根據屏幕尺寸調整物品高度以適合其RecyclerView

[英]Adjust items height to fit its RecyclerView according to screen size

我有一個帶有height:match_parent的RecyclerView ,它在適配器中以固定的高度垂直顯示16個項目。 一切工作正常,除非涉及到不同的屏幕尺寸。 在大屏幕中,顯示16個項目后,底部會保留一個空間,在小屏幕手機上,該位置正好適合底部。 我正在尋找一種方法,將列表項的高度調整到RecyclerView高度,直到最后沒有滾動。

查看下面的屏幕截圖以獲取更多說明

問題:

在此處輸入圖片說明

期望:

在此處輸入圖片說明

我的方法是將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>

針對您的問題的確切解決方案是ReyclerView的靈活布局管理器。

有關靈活布局的更多信息。

一個示例說明靈活布局的使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM