Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Y coordinate of top and bottom of ImageView

I have an image view which is contained within a relative layout. I am trying to get the screen y coordinates of the top of the image view and the screen y coordinates of the bottom of the image view. I have tried this:

 float yMin = (float)levelH.getTop();
 float yMax = (float)levelH.getBottom();

float yMin seems almost correct. I am translating another image view (IM2) up and down this image view(IM1). So I am trying to set a limit on how far (IM2) can translate up and down. So my thinking was to get the y top and bottom of (IM1) I can set those as max and min.

Anyone know how to do this?

ps Im using android accelometer to move (IM2)

like image 373
Gearóid Avatar asked Sep 12 '13 13:09

Gearóid


1 Answers

getTop() ansd getBottom() look at coordinates within it's parent. To get coordinates of it's position on the screen you can use getLocationOnScreen

Use it like this:

int[] coords = {0,0};
view.getLocationOnScreen(coords);
int absoluteTop = coords[1];
int absoluteBottom = coords[1] + view.getHeight();
like image 105
Ivo Beckers Avatar answered Nov 14 '22 02:11

Ivo Beckers