思路:
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);
}
}
效果圖,下圖點擊左邊按鈕時,事件也傳至右側了: