0

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

Ernestina Juan
  • 957
  • 1
  • 9
  • 24
  • Please look at the accepted answer on http://stackoverflow.com/questions/5777749/how-to-set-text-over-an-imageview and see if it helps you. – Actiwitty Sep 01 '15 at 21:53

2 Answers2

1

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

challenger
  • 2,184
  • 1
  • 18
  • 25
  • Yes, but I still have a problem: which font size should I use so it's the maximum value so that Text fits into the area? – Ernestina Juan Sep 01 '15 at 22:07
  • You can't know.. so you have to search for a library called AutoFit textview.. you will give height for your text view.. and the autofit textview will handle all the cases.. this subject is not simple as is seems – challenger Sep 01 '15 at 22:10
0

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.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167