ScrollView嵌套listview ,滚动问题。设置listview不滚动
对于ListView内部的ListView,一般用来展示少量的列表数据。
内部的ListView的高度看起来是一个固定值且无法滑动,这个就比较蛋疼了。、
提供两种解决方案,方案的核心都是重新设置内部ListView的高度。
1 通过定制组件,重新写一个控件,继承于ListView.
public class CustomisedListView extends ListView{
public CustomisedListView(Context context) {
super(context);
}
public CustomisedListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomisedListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
然后将这个组件作为外部ListView的Item的一部分或全部就可以了。
2 直接在代码中指定内部ListView的高度
这个也分为两种情况:
A 计算出内部ListView中的所有Item的高度
public static void reSetListViewHeight(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
这样就可以重新设置ListView的高度了
B预估出内部ListView每个Item的高度,直接写死,但感觉不如上面的好,上面的也有要求,内部ListView的Item一定得是LinearLayout
ScrollView嵌套listview ,滚动问题。设置listview不滚动的更多相关文章
- 实现ScrollView中包含ListView,动态设置ListView的高度
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...
- Android 设置ListView不可滚动 及在ScrollView中不可滚动的设置
http://m.blog.csdn.net/blog/yusewuhen/43706169 转载请注明出处: http://blog.csdn.net/androiddevelop/article/ ...
- ScrollView嵌套ListView显示不完全、嵌套TextView不能滚动解决办法
目录: 一.情景说明 二.最初做法 三.解决办法 一.情景说明 1.情景 最近项目刚好有一个需求,需要在一个界面中用ScrollView嵌套一个滚动的TextView和一个listView ...
- 关于ScrollView嵌套ListView问题
Android开发之ScrollView中嵌套ListView的解决方案 原文:http://blog.csdn.net/minimicall/article/details/40983331 ...
- 四种方案解决ScrollView嵌套ListView问题(转)
以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollVie ...
- ScrollView嵌套ListView的滑动冲突问题,是看大神的方法的,作为学习以后用的到
在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollView嵌套ListView结 ...
- 四种方案解决ScrollView嵌套ListView问题
在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollView嵌套ListView结 ...
- 转:四种方案解决ScrollView嵌套ListView问题
转载自:http://blog.sina.com.cn/s/blog_46798aa80101lxbk.html 原始的连接已经不知道是哪里了,项目中遇到了同样的问题,花了一下午都没有想到是嵌套引起的 ...
- 四种方案解决ScrollView嵌套ListView问题[转]
http://bbs.anzhuo.cn/thread-982250-1-1.html 以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多 ...
随机推荐
- How to Pronounce ‘to the’ in a Sentence
How to Pronounce ‘to the’ in a Sentence Share Tweet Share Tagged With: The Word THE, TO Reduction St ...
- avalon做的抽奖效果
.sweepstake { color: orange; font-size: 24px; font-weight: bold; } 先来一个简单的 <style> .sweepstake ...
- <cctype>库
http://www.cplusplus.com/reference/cctype/ 函数名称 返回值 isalnum() 如果参数是字母数字,即字母或数字,该函数返回true isalpha() 如 ...
- jQuery对象转换为DOM对象(转)
jQuery对象转换为dom对象 只有jQuery对象才能调用jQuery类库的各种函数,同样有些dom对象的属性和方法在jQuery上也是无法调用的,不过基本上jQuery类库提供的函数包含了所有的 ...
- 【校招面试 之 剑指offer】第16题 数值的整数次方
方法1:直接求解,但是要注意特殊情况的处理:即当指数为负,且底数为0的情况. #include<iostream> using namespace std; template<typ ...
- 【深度好文】多线程之WaitHandle-->派生-》Mutex信号量构造
bool flag = false; System.Threading.Mutex mutex = new System.Threading.Mutex(true, "Test", ...
- CFR - another java decompiler批量反编译jar文件
jd-gui众所周知,业界公认的反编译必备工具. 笔者目前遇到一个java项目,社区版,想做一个本地化的版本,询问官方,官方说闭源,无奈之下只能反编译了. 面对那么多jar,jd-gui一个个去反编译 ...
- Oracle登录命令
1.运行SQLPLUS工具 C:\Users\wd-pc>sqlplus 2.直接进入SQLPLUS命令提示符 C:\Users\wd-pc>sqlplus /nolog 3.以OS身份连 ...
- python使用input()来接受字符串时一直报错“xxx is not defined”
报错信息: “Please input your guess: gussTraceback (most recent call last): File "coinGuessGame.py& ...
- send发送一次buffer
发送的字符串后面添加:\r\n 结束标志 否则发送1024或者程序接收默认的字节数 #include <stdio.h> #include <stdlib.h> #includ ...