Android:透明视图无法正确管理触摸事件
我希望在我的应用程序上方有一个透明的视图。
我只想知道当前的活动来做到这一点。
我找到了一种方法,通过 windowManager 添加新的框架布局 我正在这样做:
public static void AddViewAbove(Activity activity) {
FrameLayout newLayout = new FrameLayout(activity);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION,
// if I let WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
// then touchevent are passed to the application behind, but I cant handle touch in
// my new frameLayout
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
activity.getWindowManager().addView(newLayout , lp);
}
我现在的主要问题是我无法在新的 FrameLayout 中以及同时在视图后面的应用程序中正确接收 touchevent。
I want to have a transparent view, above my application.
I want to do this just knowing the current activity.
I found a way of doing this by adding a new framelayout via the windowManager
I m doing this :
public static void AddViewAbove(Activity activity) {
FrameLayout newLayout = new FrameLayout(activity);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION,
// if I let WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
// then touchevent are passed to the application behind, but I cant handle touch in
// my new frameLayout
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
activity.getWindowManager().addView(newLayout , lp);
}
My main problem now is that i can't receive touchevent correctly in my new FrameLayout and in the same time in application behind my view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
还没有测试过。但想法是您需要向下传递触摸事件。由于假设您的顶级(实际上是顶部)视图处理了该事件,因此您可能需要将透明框架布局设置为不处理触摸事件(以及其他事件,如果适用)。
==更新==
您应该继承FrameLayout并创建您自己的透明布局。然后指示它监视并绕过触摸事件。 参考
==更新==
顺便说一句,您应该使用自定义框架布局(或其他适合您的布局)来“容纳”另一个孩子。我建议您可以使用它作为根布局。
Haven't tested yet. But the idea is you need to pass-thru the touch event down. Since it is assumed that your top level (and actually top) view handled the event, you might need to set your transparent framelayout to NOT handle the touch event (and other events, if applies).
==Update==
You should inherit the FrameLayout and create your own transparent layout. then instruct it to monitor and by-pass the touch event. Reference
==UPDATE==
BTW, you should use your custom framelayout (or other layout that suits you) to "hold" the other child. I suggest you can use that as your root layout.