解决ScrollView中包含ListView,导致ListView显示不全
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/id0"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/id1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/id2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border" />
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
,但我去掉此设置之后依然是可正常显示的/***
* 动态设置listview的高度
* @param listView
*/
public void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0); //在还没有构建View 之前无法取得View的度宽。在此之前我们必须选 measure 一下.
totalHeight += listItem.getMeasuredHeight();
Log.i("xxxxxxxx listItem xxxxxxxxx", i + " height : " + totalHeight);
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
// listView.getDividerHeight()获取子项间分隔符占用的高度
listView.setLayoutParams(params);
}
解决ScrollView中包含ListView,导致ListView显示不全的更多相关文章
- 解决URL中包含“%2F”导致Apache地址重写mod_rewrite失效的问题
在使用Apache地址重写mod_rewrite期间,发现,当URL和PATH_INFO中出现%2f(/)或者%5c(\), 会被认为这是个不合法的请求, Apache将会直接返回"404 ...
- 解决eclipse中maven多模块项目显示不全的问题
背景:在eclipse中导入maven项目,后来发现有的子模块不能正常的显示出现 原因:没有加载到子模块的pom文件 解决方法:重新导入:import-> 勾选项目->选择你缺少的项目的p ...
- 解决scrollView中嵌套编辑框导致不能上下滑动的问题
EditText设置maxLines之后,文本行数超过maxLines,会网上折叠,上下滑动能够浏览全部文本. 若EditText外层有scrollView.在EditText上下滑动,不会像正常情况 ...
- 解决ScrollView中的ListView无法显示全
问题描述: ListView加入到ScrollView中之后,发现只能显示其中一条,具体原因得看一下源代码.现在先贴一下方案 (转自:http://blog.csdn.net/hitlion2008/ ...
- 实现ScrollView中包含ListView,动态设置ListView的高度
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...
- scrollview 中嵌套多个listview的最好解决办法
在scrollview中嵌套多个listview的显示问题. 只需要调用如下的方法传入listview和adapter数据即可. /** * 动态设置ListView组建的高度 */ public s ...
- ScrollView中嵌套两个ListView
做的项目中要使用两个ListView在同一个页面上下显示,因为数据源不同,不能通过在Adapter中设置标志位去区分显示,最后只能硬着头皮做一个ScrollView嵌套两个ListView,但按正常情 ...
- JavaScript解决select下拉框中的内容太长显示不全的问题
JavaScript解决select下拉框中的内容太长显示不全的问题 1.说明 有些情况下,select下拉框的内容过长,导致部分看不见: 现在通过鼠标事件,让下拉框中的内容显示完全 2.实现源码 & ...
- 关于listView的item失去焦点不能点击 Item中包含Button 导致抢占焦点
今天发现一个问题.listView的item点击以后进入到下一个页面,下个页面有个返回按钮,直接返回回去以后点击事件不能触发,滑动或者重新打开这个listView,就可以达到原来的效果.后来发现是因为 ...
随机推荐
- JVM的内存划分以及常用参数
JVM的主要划分为: 堆内存,虚拟机栈,方法区,程序计数器,本地方法栈 堆内存: 这部分区域是各个线程共享的,java的大部分对象都是储存在堆中. 1.堆在分配对象内存区域的时候可以分为两种,第一种叫 ...
- WCF中序列化(XML\JSON\Dt)
序列化 是将对象转换为容易传输的格式的过程.例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象.反之,反序列化根据流重新构造对象. 序列化描述了持久化 ...
- Logistic 与 softmax
之前写的一篇感觉太 Naive ,这里重新写一篇作为总结.Logistic 与 Softmax 都是一种概率判别模型(PRML p203),Softmax 通常用在 Neural Network 里最 ...
- js document.activeElement 获得焦点的元素
<body> <input type="text" id="test" value="ajanuw"> <sc ...
- Jenkins插件管理
1.配置jenkins需要的maven.jdk路径 [root@db01 secrets]# echo $JAVA_HOME /application/jdk [root@db01 secrets]# ...
- ThinkPHP框架 祖辈分的理解 【儿子 FenyeController】继承了【父亲 FuController】继承了【祖辈 Controller】的
注:系统自带的Controller方法代表的是祖辈 FuController控制器是自定义的,代表父亲... FenyeController控制器就代表着儿子 [儿子 FenyeController] ...
- ThinkPHP框架 基础 链接数据库
在第一次成功访问应用入口文件的时候,会显示出一个系统默认的欢迎页面并自动在APPLication文件夹里生成三个文件夹,如下,第一次访问应用文件路径:localhost/tr/index.php ...
- Linux下coreseek环境安装 、mysql数据源、sphinx扩展安装及php调用
一.安装m4-1.4.13.autoconf-2.64.automake-1.11.libtool-2.2.6 下载安装m4-1.4.13.autoconf-2.64.automake-1.11.li ...
- 23. 合并K个排序链表
一种方法是分治 类似快排的例子. 第二种使用堆,比较好理解. 堆中保存一个元素是一个链表的头部. /** * Definition for singly-linked list. * public ...
- Luogu 3369 / BZOJ 3224 - 普通平衡树 - [替罪羊树]
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 https://www.luogu.org/problemnew/show/P3 ...