当前位置: 代码迷 >> Android >> 【安卓】乾坤大罗移,将器皿触摸事件传至另一容器、
  详细解决方案

【安卓】乾坤大罗移,将器皿触摸事件传至另一容器、

热度:96   发布时间:2016-04-28 04:52:49.0
【安卓】乾坤大罗移,将容器触摸事件传至另一容器、!

思路:

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);	}}


效果图,下图点击左边按钮时,事件也传至右侧了:







  相关解决方案