change an imageView to foreground and background in Android

3.6k views Asked by At

I have two ImageViews imageView1, imageView2 and they are partially intersected, I want with an OnClick or onTouch on one of theme it will be on foreground and the other one at the background relative to the other one and vice versa.

I just need the function like setOnForeGround (which does not exist) to call it for this raison.

Thanks.

4

There are 4 answers

3
Matt On BEST ANSWER

If they have the same parent, you should be able to use View.bringToFront() on either ImageView to bring it to the foreground.

0
andrei On
0
bobby.dhillon On

Ok Here is trick to do that, First create a FrameLayout and put images into that in order for four images like

1) image1 
2) image2

3) image2
4) image1

By default the visibity of 3) and 4) will be hidden. 1) and 2) is visible. When user click 2) : make 1) and 2) hidden and show 3) and 4).

Then in similar way if user clicks 4): hide 3) and 4) and show 1) and 2). Hope this will help.

0
AudioBubble On

using View.bringToFront() can be useful for you