01 public void setListViewHeightBasedOnChildren(ListView listView) { 
02     ListAdapter listAdapter = listView.getAdapter();  
03     if (listAdapter == null) { 
04         return
05     
06  
07     int totalHeight = 0
08     for (int i = 0; i < listAdapter.getCount(); i++) { 
09         View listItem = listAdapter.getView(i, null, listView); 
10         listItem.measure(00); 
11         totalHeight += listItem.getMeasuredHeight(); 
12     
13  
14     ViewGroup.LayoutParams params = listView.getLayoutParams(); 
15     params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
16     ((MarginLayoutParams)params).setMargins(10101010);
17     listView.setLayoutParams(params); 
18 }
 

[2].[代码] XML布局 跳至 [1] [2] [3] [4]

01 <ScrollView
02         android:layout_width="fill_parent"
03         android:layout_height="fill_parent"
04         android:fadingEdge = "none"
05         android:background="#FFF4F4F4"
06         xmlns:android="http://schemas.android.com/apk/res/android"
07         >
08    <LinearLayout
09     android:gravity="center_horizontal"
10     android:orientation="vertical"
11     android:background="#fff4f4f4"
12     android:layout_width="fill_parent"
13     android:layout_height="fill_parent"
14     >
15     <ListView
16         android:id="@+id/moreItemsListView"
17         android:layout_width="fill_parent"
18         android:layout_height="fill_parent"
19         android:cacheColorHint="#FFF4F4F4"
20         android:dividerHeight="0.0dip"
21         android:fadingEdge="none"
22         />
23    </LinearLayout>
24 </ScrollView>
 

[3].[图片] scrollview_listview.jpg 跳至 [1] [2] [3] [4]

 

获取并设置ListView高度的方法的更多相关文章

  1. jquery获取和设置元素高度宽度

    jquery获取和设置元素高度宽度 1.height()/ width() 取得第一个匹配元素当前计算的高度/宽度值(px) height(val)/ width(val) 为每个匹配的元素设置CSS ...

  2. 获取windows任务栏高度的方法

    方法一: TRect rt; SystemParametersInfo(SPI_GETWORKAREA, , &rt, ); //任务栏在下面的高度 int y = ::GetSystemMe ...

  3. ScrollView嵌套listview 时根据内容动态设置listview高度

    public static void setListViewHeightBasedOnChilds(ListView listView){ ListAdapter listAdapter = list ...

  4. 2013-10-7 设置combboxItem高度的方法

    //首先设置一个较大的 ItemHeight 值,比如 20: //然后设置 ComboBox 的 DrawMode 为 OwnerDrawVariable: //再设置DrawItem事件如下 if ...

  5. Android : 反射机制获取或设置系统属性(SystemProperties)【转】

    本文转载自:https://blog.csdn.net/wei_lei/article/details/70312512 Android.os.SystemProperties 提供了获取和设置系统属 ...

  6. jQuery基础之获取和设置标签元素属性

    jQuery基础之获取和设置标签元素属性方法,如下图: 代码实现: <script src="JS/jquery-1.12.4.min.js"></script& ...

  7. 实现ScrollView中包含ListView,动态设置ListView的高度

    ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...

  8. [Android Pro] listView和GridView的item设置的高度和宽度不起作用

    referece to : http://blog.csdn.net/beibeixiao/article/details/9032569 1.     在Android开发中会发现,有时listVi ...

  9. Javascript&Jquery获取浏览器和屏幕各种高度宽度方法总结及运用

    <js篇> Javascript获取浏览器和屏幕各种高度宽度方法总结 document.body.clientWidth       //网页可见区域宽(body) document.bo ...

随机推荐

  1. java中的静态代码块、构造代码块、构造方法

    运行下面这段代码,观察其结果: package com.test; public class HelloB extends HelloA { public HelloB() { } { System. ...

  2. JavaScript并非“按值传递”

    置顶文章:<纯CSS打造银色MacBook Air(完整版)> 上一篇:<拥Bootstrap入怀--模态框(modal)篇> 作者主页:myvin 博主QQ:85139910 ...

  3. Bootstrap系列 -- 25. 下拉菜单分割线

    在Bootstrap框架中的下拉菜单还提供了下拉分隔线,假设下拉菜单有两个组,那么组与组之间可以通过添加一个空的<li>,并且给这个<li>添加类名“divider”来实现添加 ...

  4. java多线程-BlockingQueue

    BlockingQueue简介 ArrayBlockingQueue:基于数组实现的一个阻塞队列,在创建ArrayBlockingQueue对象时必须制定容量大小.并且可以指定公平性与非公平性,默认情 ...

  5. 用 Docker 快速配置前端开发环境

    来源于:http://dockone.io/article/1714 今天是你入职第一天. 你起了个大早,洗漱干净带着材料去入职. 签了合同,领了机器,坐到工位,泡一杯袋装红茶,按下开机键,输入密码, ...

  6. 使用 ArcGIS中的ArcObjects进行二次开发

    参考网址:https://blogs.esri.com/esri/arcgis/2012/12/07/arcobjects-or-runtime-sdk/ http://resources.arcgi ...

  7. Git 常用命令详解(二)

    Git 是一个很强大的分布式版本管理工具,它不但适用于管理大型开源软件的源代码(如:linux kernel),管理私人的文档和源代码也有很多优势(如:wsi-lgame-pro) Git 的更多介绍 ...

  8. 虚拟机去混杂模式与 vlan in vxlan 特性

    1. 去混杂模式 1.1 背景 混杂模式(Promiscuous Mode)是指一台机器能够接收所有经过它的数据流,而不论其目的地址是否是它.是相对于通常模式(又称“非混杂模式”)而言的. 这被网络管 ...

  9. zoj3888 找第二大

    题目简化后最终要求的就是第二大的数.但是由于数据较大,不能直接求.可以先预处理,求出所有情况. #include<stdio.h> #include<string.h> #in ...

  10. std::ios::sync_with_stdio(false);

    这句语句是用来取消cin的同步,什么叫同步呢?就是iostream的缓冲跟stdio的同步.如果你已经在头文件上用了using namespace std;那么就可以去掉前面的std::了.取消后就c ...