How can I make images disappear from a grid view o

2019-09-15 17:39发布

问题:

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/