Ernestina Juan
Ernestina Juan

Reputation: 967

Android - Display text over specific position of image

In my Android app I have an ImageView which displays an image from assets. What I need to do is to display a text almost centered in the image (what I mean by almost centered is aligned to a rectangle which is near from the center of the image). I know the (x, y) coordinates of this point (in pixels), but when I switch from device to device, of course, this pixels vary. I have tried using dp, with no luck.

So, what I want to do is to display text inside this rectangle. I have the (x, y) coordinates of each point of the rectangle (in pixels relative to the emulator).

How can I do to make that design responsive?

Thank you

Upvotes: 0

Views: 819

Answers (2)

challenger
challenger

Reputation: 2214

Put the image in a relativelayout... And add the textView(with centerInParent) to the relative layout...

Upvotes: 1

Marcos Vasconcelos
Marcos Vasconcelos

Reputation: 18276

Try making the position relative to the Image not the Emulator.

So when you go across different devices you can multiply both values by the same scale factor.

Upvotes: 0

Related Questions