Looking for a way to build resolution independent layout xml?

by Videoguy » Fri, 06 Mar 2009 02:53:32 GMT

Sponsored Links
I am working on a screen that needs to look fine at HVGA-L resolution
as well as 640x480 resolution. Lets say I have a button that is 200
pixels wide and 50 pixels high on HVGA-L skin. When the same layout
xml is shown at 640x480 skin, I want my button size increase
proportionately. The hardware the app runs on supports both the

How do I do that?

None of the units that the android framework provides seems to have
this facility. If I use px, then the button size will stay same. dip
doesn't matter because it is the same hardware. sp is meant for fonts,
not for button width/heights.

Is there any trick to do this?


Looking for a way to build resolution independent layout xml?

by Videoguy » Fri, 06 Mar 2009 03:15:10 GMT

 I have lot of screens that need this. XML is a great prototyping

I am wondering whether it can be accomplished with xml layouts


Sponsored Links

Looking for a way to build resolution independent layout xml?

by Videoguy » Fri, 06 Mar 2009 12:38:28 GMT

 Hmmm...I am not sure Romain's solutions works in this case.
I dumbed down our problem. We are looking at Android to replace a
legacy kiosk type of application. The device is not a phone. We have
around 40+ different layouts (or Activities in android lingo) that
need to show correctly in half dozen resolutions. It is going to be
maintenance nightmare if we start creating resolution specific layout
files in layout_XXX/ and drawable_XXX/ folders. Everything works great
in first release, But it won't be long before the layouts in one
resolution going out of sync with their counterparts in other folders.

What would be great is if I can do something like:
   a) Specify the resolution in the layout xml (say 640x480)
   b) Build my xml that works in that resolution using whatever units
that work for the layout.

Then lets say I am showing that layout in 800x480 resolution, the
widget engine understands that the layout's native resolution
(specified in xml) is different from current system's resolution and
start scaling all the measurements, offsets to new resolution.
Basically one xml layout is used in multiple resolutions. It works
pretty good as long as you don't try 640x480 on 480x640 resolution.
This will make it even better if you combine it with layout_XXX/
method. The widget engine picks a match from layout_XXX/ folder and
doesn't do any scaling. If there is no match, it defaults to my
I understand you can achieve resolution independence with clever way
of using layout_width and layout_weight. When you have buttons with
drawables on left/right, you start using the padding attributes in px
or dip. They don't seem to position correctly when you change

If I have to implement a solution like above, what is the least
intrusive way (to the framework) of accomplishing it?
Do I need to create my own xml layout inflator and add the
translations like above?
Or did I go on a tangent?

Thanks for answering.



Other Threads

1. how to implement atuolink in Dialog?

hi bodies!
    when i want to implements a autolink func in dialog, i.e. when a
click the autolink, it will bring me the righit place: broswer, mail,
sms,and so on.
   when i do this with
                  ... ...
                 ... ...

    if i click the Ling this will be a error that say:

     android.util.AndroidRuntimeException: Calling startActivity()
from outside of an Activity  context requires the
FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

    what's happen? or how can i finish my task?


€good day!!!


2. Hello World - Unknown Error

I have just set-up the AndroidSDK in Eclipse in linux. Everything was
going smoothly until I hit the final run that would run the emulator
and start the application. I came up with an "[2009-08-29 10:28:35 -
HelloAndroid] Unknown error: " Is their a way to run the emulator by
itself just to check if its that? And any other ideas would be


3. Drawable

4. Date Limit

5. draw textview

6. PDP Status Check

7. Controling a Servo Controller? For use with robotics and sensors