I solved this problem by inspiring @nmw's answer.
You should expand the viewing group (I prefer to use LinearLayout ).
For children, ignore the mouse touch event. You must implement the onInterceptTouchEvent method.
This is a sample layout to solve this problem:
import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.LinearLayout;
public class MyLinearLayout extends LinearLayout { public MyLinearLayout(Context context) { super(context); // TODO Auto-generated constructor stub } public MyLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } boolean mChildCanCaptureTouchEvent = true; /** * @return the mChildCanCaptureTouchEvent */ public boolean ChildCanCaptureTouchEvent() { return mChildCanCaptureTouchEvent; } /** * @param mChildCanCaptureTouchEvent * the mChildCanCaptureTouchEvent to set */ public void ChildCanCaptureTouchEvent(boolean mChildCanCaptureTouchEvent) { this.mChildCanCaptureTouchEvent = mChildCanCaptureTouchEvent; } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() != MotionEvent.ACTION_MOVE) { return true; } if (!mChildCanCaptureTouchEvent) return true; return super.onInterceptTouchEvent(ev); } }
source share