導航:首頁 > 操作系統 > android獲取item高度

android獲取item高度

發布時間:2025-01-08 21:51:38

android listView 如何固定item的個數,剩下的滑動顯示

不能不定個數,只能固定高度,如果需要固定為4個item,那麼你可以算出來每個item的高度X4 ,再將listView的高度=item的高度X4。
1、配置文件里ListView高度設置為 warp_content
2、在代碼中載入ListView數據,
3、數據載入完成後(setAdapter或者notifyDataSetChanged之後),重新計算item高度,然後item X 4 = listView的高度
listView.setAdapter(adapter);
View listItem = adapter.getView(0,null,listView);
listItem.measure(0, 0);
int totalHei = (listItem.getMeasuredHeight()+listView.getDividerHeight() ) * 4;
listView.getLayoutparams().height = totalHei;

僅供參考,沒測試。你可以試試。。。

Ⅱ android 實現recyclerview item大於多少以後高度固定可以滑動

提供一個思路:你可以在父類做一個控制,由父類的布局來限制recyclerview的高度,然後根據 recyclerview要顯示的item多少計算item的高度來設置父類布局的最大高度。

Ⅲ listview怎樣設置每個Item的高度

1.在ListView的布局文件中把屬性android:layout_height設置成"wrap_content"
<ListView
android:cacheColorHint="#00000000"
android:textColor="#ff435346"
android:textSize = "20sp"
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout="@+id/textViewCurrentBase"
android:listSelector="#00000000"
android:drawSelectorOnTop="false"/>

2.設置子項xml文件(比如這里把一個item.xml設置成ListView的一行)的各個控制項android:layout_height的值。這里80sp+40sp就是你需要的一行的高度了。
item.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TextView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:focusable="false"
android:textColor="@drawable/white"
android:id="@+id/ItemTitle"
android:layout_height="80sp"
android:layout_width="fill_parent" />
<TextView android:focusable="false"
android:id="@+id/ItemText"
android:textColor="@drawable/blue"
android:layout_height="40sp"
android:layout_width="wrap_content"
android:layout_below="@+id/ItemTitle" />
<Button
android:id="@+id/ItemButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>

閱讀全文

與android獲取item高度相關的資料

熱點內容
我們買的絕地求生屬於什麼伺服器 瀏覽:413
linux網卡配置dhcp 瀏覽:284
安卓子系統文件夾 瀏覽:279
java數20個 瀏覽:867
matplotlib源碼 瀏覽:795
linux查看uid 瀏覽:17
android延時跳轉 瀏覽:180
如何模擬app對服務發出請求 瀏覽:805
程序員小陳的一天 瀏覽:700
凸多邊形凹多邊形凸包演算法 瀏覽:913
電腦如何加密碼不讓別人知道 瀏覽:909
如何用壓縮包安裝軟體 瀏覽:870
幸福工廠的app在哪裡下載 瀏覽:569
農業銀行手機app刷臉在哪裡 瀏覽:36
騰訊雲伺服器開啟命令 瀏覽:46
單片機算高科技嗎 瀏覽:754
java有序list 瀏覽:922
內容管理系統java 瀏覽:694
公眾號吸粉源碼 瀏覽:125
你無權保存到你當前文件夾 瀏覽:479