简体   繁体   English

如何在触摸时从网格视图中消失图像?

[英]How can I make images disappear from a grid view on touch?

I have a grid view with various image views within it, and I want these images to disappear when touched. 我有一个网格视图,里面有各种图像视图,我希望这些图像在触摸时消失。

How can I do this? 我怎样才能做到这一点? How can I implement a touch listener for these grid view images? 如何为这些网格视图图像实现触摸侦听器?

The ImageViews all are types of views and the layouts are ViewGroups. ImageViews都是视图类型,布局是ViewGroups。 Any of these you can set the visibility to gone or removed. 您可以将其中任何一个设置为已删除或已删除。 So really you just neeed to implement onTouchListener event handler and then set visibility on the ImageViews. 所以你真的需要实现onTouchListener事件处理程序,然后在ImageViews上设置可见性。 So you might want to consider setting a whole layout to invisible as well if you want to hide them all at once. 因此,如果您想一次隐藏它们,您可能还需要考虑将整个布局设置为不可见。 You can do 你可以做

LinearLayout myLinearLayout = (LinearLayout)findViewById(myLinearLayoutId);
myLinearLayout.setVisibility(View.GONE) // or to show again View.VISIBLE

in general 一般来说

       view.setVisibility(View.GONE) or View.INVISIBLE

For tutorial on onTouchListener see: http://www.mybringback.com/tutorial-series/3279/android-the-basics-32-androids-ontouchlistener-and-motionevent/ 有关onTouchListener的教程,请参阅: http ://www.mybringback.com/tutorial-series/3279/android-the-basics-32-androids-ontouchlistener-and-motionevent/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM