解决GridView和ScrollView滑动冲突

我们知道ScrollView和GridView以及ListView都可以上下滑,但用在一起就会造成滑动冲突,只有重写GridView或ScrollView或ListView方可解决此问题

1,重写GridView

public class GridViewForScrollView_NoNetActivity extends GridView {

    public GridViewForScrollView_NoNetActivity(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

2,重写ListView

public class GridViewForScrollView_NoNetActivity extends GridView {

    public GridViewForScrollView_NoNetActivity(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

猜你喜欢

转载自blog.csdn.net/justingwang_1/article/details/78016079