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

南楼画角 提交于 2020-01-16 08:44:10

问题


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?


回答1:


The ImageViews all are types of views and the layouts are 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. 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/



来源:https://stackoverflow.com/questions/11783374/how-can-i-make-images-disappear-from-a-grid-view-on-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!