导航:首页 > 操作系统 > 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高度相关的资料

热点内容
因为没有打开的文档所以这一命令无效 浏览:718
电脑文件夹数据损坏 浏览:716
java打赏源码搭建 浏览:363
pdf32 浏览:254
植发加密100天效果 浏览:957
离心压缩机检修规程 浏览:430
如何收听安卓手机发来的链接 浏览:399
福建微法院app怎么用 浏览:208
android陀螺仪应用 浏览:719
新加坡加密货币骗局 浏览:910
电脑文件夹打开自动变为全屏 浏览:969
简易单断面计算法 浏览:850
php社区程序 浏览:976
python现在就业怎么样 浏览:305
php上传目录权限设置 浏览:736
php合同档案管理系统 浏览:366
tshock服务器地址 浏览:877
php解析文件流 浏览:780
服务器机箱铜片有什么用 浏览:969
乐视手机如何使用原生态安卓 浏览:216