您的位置:首页 > 其它

ScrollView和listView嵌套使用

2017-04-14 08:20 225 查看
ScrollView和listView嵌套使用,会出现无法自动测量的情况,需要重写listView的测量方法。

自定义listView。

public class InnerListView extends ListView {

    public InnerListView(Context context) {

        super(context);

    }

    public InnerListView(Context context, AttributeSet attrs) {

        super(context, attrs);

    }

    public InnerListView(Context context, AttributeSet attrs, int defStyle) {

        super(context, attrs, defStyle);

    }

    

    @Override

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);

        super.onMeasure(widthMeasureSpec, expandSpec);

    }

    

}

//重写之后在布局文件中使用重写的listView。其他步骤正常使用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: