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. Want to execute arm compiled executable file on Android adb shell

I stuck in a problem.

I want a chmreader executable file to be used in android application.
Now whenever I tried to execute it from adb shell, it gives error
"permission denied"
Now, whenever I use "su" it just executes the file, but doesn't do
And whenever I give the argument as the path of the file to be read,
"# su /sdcard/extract_chmLib /sdcard/docs/{*filter*}.chm"
it shows
"su: exec failed for /sdcard/docs/{*filter*}.chm Error:Permission
"/sdcard/extract_chmLib" is the executable file and
"/sdcard/docs/{*filter*}.chm" is the chm file to be read.

Can you please help me???


2. How can I bring an activity to the front from a background service


First of all, I am aware my issue is against the philosophy of
Android, but I have no choice, this application will run on a embedded
car gps and I need to bring an activity to prevent from car accident,
for example, when it's happen around the user. I have to put other
activity on the back and bring my alert pop up without user
manipulation like notification on the front.

Is there a way to bring manually an activity to the front, by resuming
it like when you click on the android task switcher?


3. Netbeans Profiler

4. Droid Eris Virtual Keyboard

5. Restarting an activity within a tab (TabActivity)

6. MediaPlayer: Changing surfaceHolder

7. Supress the native In Call Screen and replace with 3rd party?