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

直接在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
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
				MeasureSpec.AT_MOST);
		super.onMeasure(widthMeasureSpec, expandSpec);
	}

}


你可能感兴趣的:(android,ListView,GridView,scrollview)