Android: Invisible objects still clickable

后端 未结 6 599
小蘑菇
小蘑菇 2021-01-17 11:28

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 hav

相关标签:
6条回答
  • 2021-01-17 11:37

    Try: object.setClickable(false); As an alternative, you can: object.setEnabled(false);

    0 讨论(0)
  • 2021-01-17 11:46

    Use object.setVisibility(View.GONE); instead object.setVisibility(View.INVISIBLE);

    View.GONE Means This view is invisible, and it doesn't take any space for layout purposes.

    View.GONE This view is invisible, and it doesn't take any space for layout purposes.

    View.INVISIBLE This view is invisible, but it still takes up space for layout purposes.

    I hope it will helps you .

    0 讨论(0)
  • 2021-01-17 11:46

    Try object.setVisibility(View.GONE)

    View.GONE prevents view to draw its layout bounds (width and height) whereas View.INVISIBLE draws it.

    0 讨论(0)
  • 2021-01-17 11:49

    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.

    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.

    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.

    Thanks a lot, google.

    0 讨论(0)
  • 2021-01-17 11:50

    Making any View invisible don't prevent us to trigger their listeners. It's just you can not see it every other thing would be same as if it was visible.

    If you don't want to use it at all change it to View.GONE

    Difference in View.INVISIBLE and View.GONE: Invisible objects keep on utilizing the space assigned to it while object set as View.GONE would leave the space of space as if its not on screen.

    Use

    object.setVisibility(View.GONE);
    

    rather than

    object.setVisibility(View.INVISIBLE);
    
    0 讨论(0)
  • 2021-01-17 11:55

    You should use:

    object.setVisibility(View.GONE);
    

    View.GONE removes your view completely from the layout, but View.INVISIBLE only makes your view invisible but still found in your layout, thus clickable.

    0 讨论(0)
提交回复
热议问题