Android通过在其外部单击来使视图消失 [英] Android make view disappear by clicking outside of it

查看:123
本文介绍了Android通过在其外部单击来使视图消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按下按钮后,我可以看到一些视图.如果我在这些视图之外单击,我希望它们消失.

I have some views that I make visible upon a button press. I want them to disappear if I click outside of those views.

如何在Android上完成此操作?

How would this be done on Android?

此外,我意识到后退按钮"也可以为Android用户提供帮助-我可以将其用作关闭视图的辅助方法-但某些平板电脑甚至没有使用物理"后退按钮不再强调了.

Also, I realize that the "back button" can also assist Android users with this - I might use that as a secondary way to close the views - but some of the tablets aren't even using a 'physical' back button anymore, it has been very de-emphasized.

推荐答案

一种简单/愚蠢的方式:

An easy/stupid way:

  • 创建一个虚拟的空视图(假设ImageView没有源),使其填充父级

  • Create a dummy empty view (let's say ImageView with no source), make it fill parent

如果单击,则执行您想做的事情.

If it is clicked, then do what you want to do.

您需要在XML文件中具有根标记才能成为RelativeLayout.它包含两个元素:虚拟视图(将其位置设置为align the Parent Top).另一个是您的原始视图,其中包含视图和按钮(此视图可以是LinearLayout或您使用的任何东西.请不要忘记将其位置设置为align the Parent Top)

You need to have the root tag in your XML file to be a RelativeLayout. It will contain two element: your dummy view (set its position to align the Parent Top). The other one is your original view containing the views and the button (this view might be a LinearLayout or whatever you make it. don't forget to set its position to align the Parent Top)

希望这对您有帮助,祝您好运!

Hope this will help you, Good Luck !

这篇关于Android通过在其外部单击来使视图消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆