如果scrollview中镶嵌一个listview的话,无论listview的高和宽设置成wrap还是match,都会出现无法显示全部的现象,那么我们如何解决这个问题呢。
我们只需要重写listview的高度,代码如下:
public class MyListview extends ListView {
public MyListview(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyListview(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyListview(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
return super.dispatchTouchEvent(ev);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
int expend = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expend);
}
}
布局文件中只需要
<com.my.coustomview.MyListview
android:id="@+id/set_mylistview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/set_include1" >
</com.my.coustomview.MyListview>