Looking for a way to build resolution independent layout xml?

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


Sponsored Links
 Hi
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
resolutions.

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?

Thanks
Videoguy
--~--~---------~--~----~------------~-------~--~----~



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
tool.

I am wondering whether it can be accomplished with xml layouts
though.

--~--~---------~--~----~------------~-------~--~----~


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
solution.
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
resolution.

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.

Videoguy






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to create a socket in Andriod

Hi,

i have this source code:

My Rcb.java line 216 is
 sock = new Socket(host, port);

// where host is 127.0.0.1 and port = 6901

And I run my application under android, I get this exception:
11-18 16:35:21.565: WARN/System.err(165): java.net.SocketException:
unknown error
11-18 16:35:21.585: WARN/System.err(165):     at
org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl
(Native Method)
11-18 16:35:21.595: WARN/System.err(165):     at
org.apache.harmony.luni.platform.OSNetworkSystem.createSocket
(OSNetworkSystem.java:79)
11-18 16:35:21.615: WARN/System.err(165):     at
org.apache.harmony.luni.net.PlainSocketImpl2.create
(PlainSocketImpl2.java:59)
11-18 16:35:21.635: WARN/System.err(165):     at
java.net.Socket.startupSocket(Socket.java:668)
11-18 16:35:21.655: WARN/System.err(165):     at java.net.Socket.<init>
(Socket.java:142)
11-18 16:35:21.665: WARN/System.err(165):     at com.mytest.Rcb.<init>
(Rcb.java:216)
11-18 16:35:21.685: WARN/System.err(165):     at
com.mytest.TestActivity.onCreate(VncTestActivity.java:21)
11-18 16:35:21.695: WARN/System.err(165):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1122)
11-18 16:35:21.705: WARN/System.err(165):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2103)
11-18 16:35:21.715: WARN/System.err(165):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2156)
11-18 16:35:21.725: WARN/System.err(165):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
11-18 16:35:21.735: WARN/System.err(165):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
11-18 16:35:21.745: WARN/System.err(165):     at
android.os.Handler.dispatchMessage(Handler.java:88)
11-18 16:35:21.755: WARN/System.err(165):     at android.os.Looper.loop
(Looper.java:123)
11-18 16:35:21.765: WARN/System.err(165):     at
android.app.ActivityThread.main(ActivityThread.java:3742)
11-18 16:35:21.775: WARN/System.err(165):     at
java.lang.reflect.Method.invokeNative(Native Method)
11-18 16:35:21.785: WARN/System.err(165):     at
java.lang.reflect.Method.invoke(Method.java:515)
11-18 16:35:21.785: WARN/System.err(165):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:739)
11-18 16:35:21.795: WARN/System.err(165):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
11-18 16:35:21.805: WARN/System.err(165):     at
dalvik.system.NativeStart.main(Native Method)

Thank you for any help.


--~--~---------~--~----~------------~-------~--~----~

2. Activity.setResult(RESULT_OK, intent) resulting in RESULT_CANCELED

I am trying to pass a jpeg from the camera back to the calling
activity.  From a Handler I call activity.setResult(RESULT_OK, intent)
where intent is a new Intent() with a Bundle containing the jpeg.  In
the onActivityResult() of the original caller, though, I get a
resultCode of RESULT_CANCELED.  If I instead call activity.setResult
(RESULT_OK) the resultCode remains OK.

Does anyone have any hints on how best to track this down or what to
look for?

Thanks!

--~--~---------~--~----~------------~-------~--~----~

3. Emulator touch input vs real phone input--differences?

4. Writing an Android App

5. how to start the default music application from my own application

6. Not able to read data from shell command

7. android.app.Instrumentation result bundle