by Bobbie » Tue, 10 Feb 2009 10:49:17 GMT

Sponsored Links
 I have a couple different questions:

1) Does Google think there will only be one screen size on Android
phones?  The reason I ask is because I haven't been able to find
anything on "variable" layouts in Android?  I would like to create a
layout with 2 webviews, one 80% of screen height and the other 20%.
Is this even possible, or do I need to assign the height of each as a
static "px" value?

2) How do I preserve the data in my views when someone switches
between landscape and portrait?  I doubt it's hard, but I've not been
able to find it.  Can someone post an example?

Thanks everyone!


by Romain Guy » Tue, 10 Feb 2009 12:05:13 GMT

 > 1) Does Google think there will only be one screen size on Android


All layouts are variable.

That's what wrap_content, fill_parent, weight and in some measure the
dip unit are for.

It's done automatically for all the views with an id.

Romain Guy
Android framework engineer

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them


Sponsored Links


by Marco Schmitz » Tue, 10 Feb 2009 21:11:38 GMT

 try to create a folder "layout-land" and "layout-port" next to "layout".

just place main.xml inside both folders but not inside "layout".

swapping the layout (numlock+7 inside the emulator) will show you the
best fitting xml file.


2009/2/10 Romain Guy <>:



by Bobbie » Tue, 10 Feb 2009 22:25:28 GMT

 I tried using fill_parent, but somewhere I still have to specify a
"percentage" screen height instead of a "px" value, that's what I'm
having issues with.  Can you post an example of how to do an 80%
screen height with a 20% screen height below it?



by Ludwig » Tue, 10 Feb 2009 22:52:56 GMT

 2009/2/10 Bobbie <>

Android caters for different screen sizes already. The Openmoko Freerunner
runs Android quite happily on a larger resolution than the G1. If you edit
the skins for your emulator (they are just text files) it is quite easy to
simulate larger (or smaller) screen sizes for development.

Pretty much all layouts are 'variable', apart from the fixed ones: a
ListView will have more lines on a larger screen etc.

What you are after is the android:layout_weight="x" attribute for your view
elements. In your case you want, probably inside a LinearLayout, two
elements, one with a weight of 4, the other 1. The weights are relative, so
the first will get 80% of screen height, the other 20.





by Bobbie » Wed, 11 Feb 2009 19:09:37 GMT

 Ok, so I'm having trouble with this.  What I'm trying to do is design
a web-based chat interface using 2 webviews (one for the message
display and one to send messages).  I have the code for everything
ready and it works, I just need to figure out the whole layout thing.
Here is the code I have:

<?xml version="1.0" encoding="utf-8"?>
xmlns:android="" ;

The program runs in landscape mode.  The problems I am running into

1) The "chatview" webview is showing up at the bottom instead of the

2) When I hit the "back" button the app crashes.  I'm guessing this is
because the interface isn't designed right, but I could be wrong.



Other Threads

1. MediaPlayer blocked(AudioFlinger write blocked) while playing animation

Hi all,

I have a thread to play audio and animation together. It's a frame
animation. The drawable resources are in sdcard. When I play the
animation, I use a handler to send message to refresh images one by
Here's my code:
final Handler handle = new Handler(){
     public void handleMessage(Message msg){
          BitmapDrawable bmpDraw = new BitmapDrawable("sdcard/
          if(msg.what < fileNames.length-1){
MediaPlayer mp = new MediaPlayer();
...//play audio

The animation performs fine, but the audio will be stopped when it
begins to play for seconds. From logcat I see AudioFlinger: write
blocked for 89 msec...

I don't use AnimationDrawable because there are many images in sdcard,
when I use addFrame(AnimationDrawable.createFromPath(...)) I got an
OutOfMemory Exception.

Am I doing the right thing? Can anyone help me?


2. How to close all activities on android app

Hi for all

I'he a android app with 5 activities and i would close all open
activities by pressing a button, for example. How I do it exactly?
What is the better strategy? Somebody can help me?


3. TransitionDrawable with different sized bitmaps

4. Saving an image

5. how to give effects to livewallpaper?

6. StartActivityForResult

7. comparison of Thread vs Asynctask in android?