Android:看不见的对象仍可点击 [英] Android: Invisible objects still clickable

查看:133
本文介绍了Android:看不见的对象仍可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,其中包含按钮和图像,这些按钮和图像可以根据用户的交互而显示和消失.

I have an activity that has buttons and images that can appear and disappear depending on user interactions.

我发现的是,后面的对象(已设置为不可见)仍在触发点击.他们没有处理与被单击相关的代码,但是它们会暂时重新出现,然后在被单击时立即再次消失.

What I am finding is that objects at the back, which have been set to invisible, are still triggering clicks, sort of. They are not processing the code related to being clicked, but they sort of momentarily reappear, and then disappear again instantly when clicked on.

它们似乎也干扰了位于其顶部的按钮.当这些按钮后面有看不见的对象时,这些按钮变得非常轻巧,有时很难单击.

They also appear to be interfering somewhat with buttons laid over the top of them. These buttons become very fiddly and difficult to click at times, when there is an invisible object behind them.

我正在简单地使用:

object.setVisibility(View.VISIBLE);

并且:

object.setVisibility(View.INVISIBLE);

使我的物品显示和消失.这不是我应该做的吗?

To make my items appear and disappear. Is this not what I should be doing?

人们一直在问我他们给我的完全相同的代码.这是我已经提供的代码,目前正在使用.

People keep asking me for the exact same code that they are giving me. This is the code I have been given, and that I am using currently.

        btnLifePlus5.setVisibility(View.GONE);
        btnLifePlus5.setFocusableInTouchMode(false);
        txtLifePlus5.setVisibility(View.GONE);
        txtLifePlus5.setFocusableInTouchMode(false);
        btnLifePlus1.setVisibility(View.GONE);
        btnLifePlus1.setFocusableInTouchMode(false);
        txtLifePlus1.setVisibility(View.GONE);
        txtLifePlus1.setFocusableInTouchMode(false);
        btnLifeMinus5.setVisibility(View.GONE);
        btnLifeMinus5.setFocusableInTouchMode(false);
        txtLifeMinus5.setVisibility(View.GONE);
        txtLifeMinus5.setFocusableInTouchMode(false);
        btnLifeMinus1.setVisibility(View.GONE);
        btnLifeMinus1.setFocusableInTouchMode(false);
        txtLifeMinus1.setVisibility(View.GONE);
        txtLifeMinus1.setFocusableInTouchMode(false);

这与将它们设置为不可见没有区别.

This makes no difference to just setting them as invisible.

推荐答案

我设法解决此荒谬问题的唯一方法是创建一种视图面板,该面板位于活动对象之间.该视图面板是屏幕的大小,使用相同的颜色背景,并且开始不可见.

The only way I managed to solve this ridiculous issue was to create a sort of view panel that sits between the objects in my activity. This view panel is the size of the screen, uses the same colour background, and starts invisible.

通常,我使对象A消失,使对象B出现.当我单击先前由对象A占用的空间时,它会瞬间闪回到屏幕上,然后再次消失.看起来糟透了.直到我下次使对象A消失时,随后的单击才会重现此错误.

Normally, I make object A disappear, and make object B appear. When I click the space previously occupied by object A, it momentarily flashes back onto the screen and then disappears again. It looks terrible. Subsequent clicks do not reproduce this bug until the next time I make object A disappear.

解决方法是使对象A消失,使新的视图面板在其顶部可见,然后使对象B出现在视图面板的顶部.因此,面板充当隐藏对象和用户交互之间的一种屏障.用户不知道该视图面板是否存在,因为它已经融合到标准背景中,但是当我现在单击对象A所在的空间时,它现在不再瞬间闪烁回到屏幕上.虽然这不是必须使用的解决方案,但该操作系统存在问题,我别无选择.

The fix is to make object A disappear, make the new view panel visible on top of it, and then make object B appear on top of the view panel. So the panel acts as a sort of barrier between the hidden object, and user interactions. The user is not aware that this view panel even exists, as it blends in to the standard background, but when I now click the space where object A would be, it now no longer flashes back onto the screen momentarily. While this is a poor solution to have to use, this OS is bugged and I am left with no choice.

我的活动现在看起来非常稳定并且运行良好.我不喜欢它,但是可以.

My activity now looks as though it is perfectly stable and working perfectly. I don't like it, but it works.

非常感谢,谷歌.

这篇关于Android:看不见的对象仍可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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