Elva
Elva

Reputation: 196

Android:How to get the coordinate of a view(not include Actionbar)

Using View.getLocationOnScreen()can get the coordinate, but it is a little larger than I expected, so I think the coordinate I get is relative to the full screen (which including ActionBar) . Is there any method can I get the coordinate without includig ActionBar? See the picture below.

I want the green 'y',not the yellow one

Upvotes: 4

Views: 1151

Answers (1)

shayan
shayan

Reputation: 220

please first see this image:

enter image description here

This link show you how get the current position of button(110 in picture)

How to get the absolute coordinates of a view

The second link calculate the Actionbar height(72 in picture)

How to get the ActionBar height?

And the last link show you how to calculate the Statusbar(38 in picture)

Height of status bar in Android

And now you can get the current position with this equal(110 = 72 + 38)

Hope to help you.

Upvotes: 1

Related Questions