直接在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); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-05 14:14:54