如何在ScrollView 中如何嵌入ListView
在ScrollView 添加一个ListView 会导致listview 控件显示不全,通常只会显示一条,这是因为两个控件的滚动事件冲突导致。网上也有许多方法,下面这个放发个人觉得很好
自定义ListView,重载onMeasure()方法,设置全部显示。
/**
* scrollview 中内嵌listview 的简单实现
*/
public class ScrollViewWithListView extends ListView {
public ScrollViewWithListView(android.content.Context context,
android.util.AttributeSet attrs) {
super(context, attrs);
}
/**
*重写onMeasure()方法
* Integer.MAX_VALUE >> 2如果不设置,系统默认设置是显示两条
*/
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}

本文介绍了解决ScrollView中嵌入ListView显示不全的问题。通过自定义ListView并重载onMeasure()方法,可以确保ListView内的所有项都能正确显示出来。
1084

被折叠的 条评论
为什么被折叠?



