Reputation: 13965
I have a view and I need to get it's top and bottom location on the screen. So I run the following experiment: Trying to figure out what hit rectangle does, I run the following experiment
int[] location = { 0, 0 };
myView.getLocationOnScreen(location);
Rect outRect = new Rect();
myView.getHitRect(outRect);
Then I print and got
outRect.top = 18
outRect.bottom = 138
location[0] = 216
location[1] = 387
I was expecting outRect.top
and location[1]
to be the same.
So, how do I get the top and bottom location of my rectangular view?
Upvotes: 0
Views: 234
Reputation: 1636
getLocationOnScreen()
returns the X and Y position of the view relative to the screen: you can calculate the bottom position by adding the value of getHeight() to the Y position. getHitRect()
returns the position of the view relative to its parent, which is why you're getting different numbers.
Upvotes: 1