Android学习之ScollView嵌套ListView和GridView问题

来源:互联网 发布:vba 数组定义同时赋值 编辑:程序博客网 时间:2024/06/05 15:14

直接在ScollView中嵌套ListView和GridView的话,ListView和GridView只会显示一部分内容,不能显示完整,需要重写ListView和GridView中的onMeasure方法,代码如下:

下面是重写ListView,GridView用法相同。

public class MyListView extends ListView {public MyListView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);// TODO Auto-generated constructor stub}public MyListView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}public MyListView(Context context) {super(context);// TODO Auto-generated constructor stub}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {// TODO Auto-generated method stubint expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);super.onMeasure(widthMeasureSpec, expandSpec);}}


2 1