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

热点内容
程序员的工资是涨的吗 浏览:811
视频存储服务器可以干什么 浏览:461
创建文件夹安装失败怎么回事 浏览:830
程序员高考隔了几年 浏览:820
云服务器是哪一层 浏览:20
jit编译器的jit什么意思 浏览:328
我想清理手机中空白文件夹 浏览:974
电脑e盘文件夹删不掉怎么办 浏览:605
外圆凹圆弧编程 浏览:459
html5编程题 浏览:837
干燥机制冷压缩机一开就跳动 浏览:386
吉林压缩空气流量监测 浏览:616
根据地址获取经纬度php 浏览:10
小天才app的应用中心有什么应用 浏览:768
java代码整理 浏览:260
安卓单个胎压怎么配对 浏览:627
linux将文件清空 浏览:476
一套前端编译平台 浏览:598
安卓9x用什么框架 浏览:72
万用表怎样量压缩机漏电 浏览:548