public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int newHeight=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, newHeight);
}
@Override
protected boolean dispatchTouchEvent(MotionEvent event) {
return super.dispatchTouchEvent(evnet);
}
}
作者:frimary
来源:优快云
原文:https://blog.youkuaiyun.com/frimary/article/details/78862475
版权声明:本文为博主原创文章,转载请附上博文链接!
本文详细介绍了一种自定义的ListView子类MyListView的实现方式,该类通过重写onMeasure方法来改变其测量行为,确保了在不同屏幕尺寸下ListView能够适配并展示更多的内容。同时,对dispatchTouchEvent方法进行了覆盖,以处理触摸事件。
3206

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



