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

熱點內容
阿里雲域名本地伺服器 瀏覽:453
資料庫地址伺服器 瀏覽:2
路由器加密碼登錄不上 瀏覽:813
qq可以加密密碼 瀏覽:854
網上認證無法連接網站伺服器地址 瀏覽:920
java資料庫建表 瀏覽:172
linux本地埠 瀏覽:36
郵票目錄pdf 瀏覽:378
解壓筆真的有用嗎 瀏覽:538
plc語法和編程語句 瀏覽:115
南航app學生旅行產品在哪裡 瀏覽:240
漫畫pdf網盤 瀏覽:495
手機pdf字太小 瀏覽:892
解壓縮安裝圖解 瀏覽:257
安卓如何查看運行伺服器 瀏覽:681
土質學pdf 瀏覽:995
郵箱收發伺服器地址 瀏覽:144
web前端和python 瀏覽:639
定址演算法 瀏覽:783
車床編程ijk之間的關系 瀏覽:493