How to handle touch outside the view in Android?(如何在Android中处理视图外的触摸?)
问题描述
我找到了 "撤消栏" 用于 Android 的 Gmail 应用程序.UndoBar"基本上是一个显示在布局顶部的视图.
I've found implementation of "Undo Bar" used in Gmail application for Android. "UndoBar" is basically a View that is displayed on top of the layout.
不幸的是,它不完整 - 它没有通过触摸栏外的屏幕来关闭栏的功能.
Unfortunately it's not complete - it has no functionality of dismissing bar by touching screen outside the bar.
我已经实现了 FrameLayout,它覆盖了 onInterceptTouchEvent 来处理 bar 的关闭,但触摸 Action Bar 什么也没做.
I've implemented FrameLayout that overrides onInterceptTouchEvent to handle bar dismissing but touching Action Bar does nothing.
有什么方法可以处理来自操作栏的此类事件?
Is there any way to handle such events from Action Bar?
下面有一个带有UndoBar"的图像.我想要在红点表示的操作栏中处理触摸.
Below there is an Image with "UndoBar"shown. What I want to achieve to handle touch in Action bar represented by red dot.
推荐答案
尝试重写你的activity的dispatchTouchEvent.
Try to override dispatchTouchEvent of your activity.
dispatchTouchEvent(MotionEvent event){
int x= event.getRawX();
int y= event.getRawY();
if(/*check bounds of your view*/){
// set your views visiblity to gone or what you want.
}
//for prevent consuming the event.
return super().dispatchTouchEvent(event);
}
更新
dispatchTouchEvent(MotionEvent event){
int x= event.getRawX();
int y= event.getRawY();
return super().dispatchTouchEvent(event)||[YourView].onTouch(event);
}
这篇关于如何在Android中处理视图外的触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在Android中处理视图外的触摸?
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
