0

This is the scenario:

I have one image background set on an activity. On this background, a rectangle has been drawn (in other words, one image depicting a rectangle). I need to display text WITHIN this rectangle.

Right now, I have one solution in mind: since I'm going to optimize the UI for most screens (incl. tablets), I'm going to customize the main .xml layout for each screen size (multiple .xml layouts). Thus, I can manually set the place where the text area goes within the rectangle (+ its size).

I am most certain that this solution is NOT good. I'd like to hear some suggestions from more advanced developers. What would an elegant way of placing text over a background image showing a rectangle, so that the text stays within the rectangle's borders be?

Because I need to set particular positions for other UI elements (centered buttons (vertically/horizontally), I am currently using a Relative Layout.

1 Answers1

0

By default if you have used dp as dimensional measure, your app should in theory work fine for all resoultions. Android by default scales the screen to fit different screens. AndroidDeveloper You just have to make sure that you have different images for resources (Rectangle image). There is another post in SO which you might be intrested to look into link

Cheers RIchie

Community
  • 1
  • 1
Richie
  • 9,006
  • 5
  • 25
  • 38
  • So, basically, pixel at 100x100 in the original image is equal to pixel at 100x100 dp on the device's screen? –  Jan 31 '12 at 16:13
  • Or, if the rectangle is located 100 pixels to the left in the original image, and I set the left margin of the text area to 100dp in the Activity, then the text area will always start at the position of the rectangle? –  Jan 31 '12 at 16:15
  • Density-independent Pixels(dip or dp) - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. – Richie Feb 01 '12 at 09:22
  • Still confused. Just throw a simple answer. You have this image: http://www.bartelme.at/material/organicdesktops/desktop_01.png . You set it as a background in a XML layout. You want a text area to be placed WITHIN the blue rectangle's borders, and stretched until it meets the blue rectangle's borders. How do you keep the text area's size and position equal to the blue rectangle's and still provide the same layout quality on all displays? –  Feb 01 '12 at 19:39
  • OK..first you have to have 1 image of each resolution put into hdpi,mdpi and ldpi image folders.Then all you have to do is,align/stretch textarea to fit your needs in it(make sure, you do the adjustments in dp rather than in px). Theorotically (as per the android developer doc) this would be rendered in the same way in all the different resolution devices. – Richie Feb 02 '12 at 10:27