思路:
1.基于view.dispatchTouchEvent
作用:
1.点击时,透过容器点到不是其子控件的控件、!
2.透过透明activity或dialog,将事件传至下方的activity、!
注:1>还可通过MotionEvent.obtain(downTime, eventTime, action, x, y, metaState);模拟事件,如用于引导中、!
被点击的容器:
public class MyLinearLayout extends LinearLayout { public MyLinearLayout(Context arg0, AttributeSet arg1) { // TODO Auto-generated constructor stub super(arg0, arg1); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub MotionEvent event2 = MotionEvent.obtain(ev); //MainActivity.llTest为目标容器,即将事件复制一份分发至llTest MainActivity.llTest.dispatchTouchEvent(event2); return super.onInterceptTouchEvent(ev); } }
效果图,下图点击左边按钮时,事件也传至右侧了: