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

熱點內容
程序員掉入能力陷阱 瀏覽:669
中百超市多點app如何充值 瀏覽:331
仙劍奇俠傳4codex未加密 瀏覽:193
如何搭建伺服器ss埠 瀏覽:56
國外代理伺服器地址伺服器埠密碼 瀏覽:754
phpthrownew 瀏覽:681
java從入門到精通pdf百度雲 瀏覽:55
linuxhdf5安裝 瀏覽:469
java繼承編程練習題 瀏覽:652
雲記app怎麼寫字視頻 瀏覽:598
如何進入我的世界臟小豆的伺服器 瀏覽:42
哪裡找到轉轉app 瀏覽:580
蘋果二次app怎麼注冊 瀏覽:587
國際服體驗服伺服器為什麼爆滿 瀏覽:114
微信商城模板源碼 瀏覽:436
網頁的源碼怎麼讀取 瀏覽:402
ubuntu命令打開軟體 瀏覽:761
如何實現對講頻道加密 瀏覽:351
福州8000的程序員去深圳多少 瀏覽:645
保存加密是什麼意思 瀏覽:43