導航:首頁 > 操作系統 > 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高度相關的資料

熱點內容
單片機串口發射怎麼回事 瀏覽:472
程序員假裝自己很忙 瀏覽:798
程序員能力關鍵詞 瀏覽:615
plc編程高級視頻教程 瀏覽:610
java遞歸求n 瀏覽:84
python絕對路徑導入 瀏覽:126
nex5g加密 瀏覽:975
18的空島伺服器地址 瀏覽:86
程序員要學什麼硬體 瀏覽:666
股票漲跌源碼怎麼看 瀏覽:578
加密軟體做法 瀏覽:57
美國程序員有多少中國人 瀏覽:741
人民日報app里怎麼看新聞早班車 瀏覽:587
忘了app怎麼辦 瀏覽:531
如何用雲伺服器做雲平台 瀏覽:301
非箍筋加密區剪力 瀏覽:119
利聯科技伺服器卡怎麼辦 瀏覽:386
js和python哪個好 瀏覽:463
c盤的哪些文件夾沒用 瀏覽:83
文件為什麼會超出在線解壓限制 瀏覽:591