首页 > 移动平台 > 详细

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

时间:2018-02-07 11:14:01      阅读:228      评论:0      收藏: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);
	}
}


效果图,下图点击左边button时,事件也传至右側了:

技术分享图片






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

原文:https://www.cnblogs.com/zhchoutai/p/8425492.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!