0

suppose i have two image view v1,v2.

imageview v1,v2;

    v1=(Imageview)findviewbyId(R.id.view1);
    v2=(Imageview)findviewbyId(R.id.view2);

How do I check that v1 ontop of v2 or not.

bhoot4242
  • 271
  • 1
  • 2
  • 9

5 Answers5

0

You can set onclick listener for both of it so that when the user clicks so that the top of the imageview only gets clicked. By this u can get which imageview is up top.

Jai Kumar
  • 920
  • 1
  • 7
  • 14
0

you may check by getting co-ordinates of the image by using this link

and can check which image is top and which is bottom with that co-ordinates

Community
  • 1
  • 1
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
0

one suggestiton: get their location and height minus them and configure if on top of

JaveZh
  • 184
  • 3
0

You can calculate it with the position and the width and height of the View.

Position: Use View.getLocationOnScreen() and/or getLocationInWindow().
Width/height: Use View.getWidth() and View.getHeight().

Johannes
  • 737
  • 5
  • 10
0

The view that is defined first in your xml layout will be drawn first. The next view will be drawn on top of the previous view if there is any.

By that principle, you can ask your frame/relative layout to check the ordering where the child views are ordered:

int indexV1 = layout.indexOfChild(v1);
int indexV2 = layout.indexOfChild(v2);
if(indexV1 < indexV2) {
    // v1 is below v2
}
Neoh
  • 15,906
  • 14
  • 66
  • 78
  • huh your code has nothing to do if it's on top of another View just the position in within ViewGroup – Johannes Jun 14 '13 at 12:01