Get Location of an ImageView

I am currently working with onDraw(); and custom shapes.

What I am trying to do here is to draw 3 lines on the blue rectangle below:

enter image description here

And display a person's speed range settings and their current speed by drawing 3 lines. I am planning to do the speed range through getting the location, the width and the height of the rectangle and then dividing this up by the range set by the user.

However, I cannot find a resource that allows me to get the location, width and height of the blue rectangle.

Is there any way to achieve this, or do I simply have to get it from the source XML?

Upvotes: 1

Views: 796

Answers (1)

7heaven
7heaven

Reputation: 807

for getting the location of view related to parent view:

float x = view.getX();

float y = view.getY();

for getting the location of view related to Screen:

int[] location = new int[2];

view.getLocationOnScreen(location);

int x = location[0];
int y = location[1];

Upvotes: 2

Related Questions