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. Video play error

Hi to all

     I am playing 2 videos(.mpg4) at time... Some times its works
fine, But some times give
error like "Cannot Play the Video" Can any One tell me Why its

Thank You
Nithin N V

2. Content Provider notifications?



3. Get Assisted GPS server address from device

4. How can I style a button widget.

5. PV software encoder with QVGA resolution

6. Reflection fails on large class

7. How does HierarchyViewer works ??