android 设置view最大高度,android-在RecyclerView上设置最大高度
我有一個對話框片段,其中包含線性布局,其中涉及RecyclerView上方的titleText,在最底部,recyclerView下方有一個按鈕.
由于recyclerView根據(jù)適配器設(shè)置的項(xiàng)目數(shù)展開或折疊,因此按鈕有時會被截?cái)嗖⑶也辉亠@示在屏幕上,因?yàn)閞ecyclerView僅覆蓋整個屏幕.
我的問題是,有沒有一種方法可以設(shè)置recyclerView的最大高度,而無需隱藏下面的按鈕.我也不想只是給視圖一個隨機(jī)的高度,以防萬一recyclerView不包含任何項(xiàng)目,而這只是一個空白部分.
如果您遇到過此問題,以及如何解決此問題,請告訴我.謝謝!
解決方法:
更新
您可以使用布局權(quán)重輕松實(shí)現(xiàn)此目的.這是一個例子:
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Title"
android:textSize="21sp"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="30dp">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Submit"/>
Title和RecyclerView將根據(jù)內(nèi)容包裝內(nèi)容,而按鈕將始終占據(jù)底部.
標(biāo)簽:android-recyclerview,android-layout,android
來源: https://codeday.me/bug/20191026/1938097.html
總結(jié)
以上是生活随笔為你收集整理的android 设置view最大高度,android-在RecyclerView上设置最大高度的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国产方德桌面操作系统5.0发布:适配10
- 下一篇: 【转】10分钟精通SharePoint