The recently -made thing involved the problem of blocking gridView shielding sliding.
1. Simple ListView and GridView shield
Two controls to block the sliding method of sliding are the same. They use the incident distribution mechanism. There is just a gridView here, which is used as an example. It’s the code, it’s relatively simple
public class MyGridview extends GridView { public MyGridview(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyGridview(Context context, AttributeSet attrs) { super(context, attrs); } public MyGridview(Context context) { super(context); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { //The following sentence is the key if (ev.getAction()==MotionEvent.ACTION_MOVE) { return true; } return super.dispatchTouchEvent(ev); } }
I see that there are more complicated incident distribution, because the method here can solve my problem, so I did not list others.
2, ListView nested GridView or scrollView nestle, nested
Since both ListView and GridView have inherited from scrollView, some conflicts will occur when nested. Here we solve this problem from the height of the new control control.
public class MyGridview extends GridView { public MyGridview(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyGridview(Context context, AttributeSet attrs) { super(context, attrs); } public MyGridview(Context context) { super(context); } /** * Settings do not roll */ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }