1
\$\begingroup\$

I'm trying to make a levels map page that shows number-buttons in the page. I want to make this page in a XML layout file and I'm actually trying to make something like this:

enter image description here

I know that I should provide a picture for the background and the background is not a problem, but I'm trying to place those buttons in certain places. I can do that by assigning margins to the buttons but then it won't show up the same way on a bigger or a smaller screen. Is there any way to do this?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

If you want to define the positions of the buttons independant of the screen resolution, you might want to use a relative coordinate system. So a single screen is defined as a 0 (left border) to 1 (right border) and 0 (top) and 1 (bottom).

So a button halfway to the screen is at 0.5 , 0.5. To calculate the actual position, multiply the axis by the screen dimension of that axis. So if the screen is 320 pixels wide, the button appears at 0.5 * 320 = 160 pixels.

In the example your map screen may appear bigger than a single display, so a y coordinate of 2.6 is perfectly valid.

\$\endgroup\$
3
  • \$\begingroup\$ What if you had two different screens with different ratios? (and obviously, wanted to keep the ratio of background by cutting the brown sides) \$\endgroup\$
    – wondra
    Sep 28, 2015 at 10:31
  • \$\begingroup\$ you could still use this system. If you want to keep buttons aligned with backgrounds, you could also use the relative system and use the width and height of the image as multiplication factors. \$\endgroup\$
    – Felsir
    Sep 28, 2015 at 10:36
  • \$\begingroup\$ ...and that was probably OP asking for. \$\endgroup\$
    – wondra
    Sep 28, 2015 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .