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

熱點內容
加密軟體做法 瀏覽:54
美國程序員有多少中國人 瀏覽:739
人民日報app里怎麼看新聞早班車 瀏覽:584
忘了app怎麼辦 瀏覽:528
如何用雲伺服器做雲平台 瀏覽:298
非箍筋加密區剪力 瀏覽:116
利聯科技伺服器卡怎麼辦 瀏覽:383
js和python哪個好 瀏覽:460
c盤的哪些文件夾沒用 瀏覽:80
文件為什麼會超出在線解壓限制 瀏覽:588
python類實例化對象 瀏覽:794
硬碟dos外部命令 瀏覽:792
做演算法還是開發 瀏覽:872
按鍵精靈自定義圖層命令 瀏覽:353
魅藍3手機音視頻文件夾 瀏覽:945
安卓手機製表怎麼換行 瀏覽:215
牆柱搭接箍筋怎麼加密 瀏覽:456
怎麼加密不讓人打開 瀏覽:336
2g3g演算法 瀏覽:206
python可以在net開發 瀏覽:934