Layout Based on Orientation

by Scoz » Sun, 07 Sep 2008 04:30:35 GMT


Sponsored Links
 Currently trying to have a dialog that will allow the user to sign in
to a service using a Webview. Using a simple LinearLayout works while
while the phone is held in portrait mode, with the message and button
on top leaving a nice squareish webview. When switching in to
landscape mode though I end up with an unusably low height webview as
the message and button are still on top.

Is there any way to specify a layout based on the current orientation?

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



Layout Based on Orientation

by Mark Murphy » Sun, 07 Sep 2008 04:33:32 GMT


 


Sure. Put one layout in res/layout and another in res/layout-land. Here, 
layout-land effectively means "use this layout when the device is in 
landscape orientation".

When the device is rotated, your current activity will be closed 
(shortly after onSaveInstanceState() is called) and then restarted with 
the appropriate layout set. Reload your widgets from the instance state 
supplied to onCreate()/onRestoreInstanceState(), and you're set.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 1.1 Published!

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


Sponsored Links


Layout Based on Orientation

by Scoz » Sun, 07 Sep 2008 07:59:15 GMT


 Awesome, this is exactly what I needed, thanks :D






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



Other Threads

1. Checkbox with multiple lines with different font size

I am trying to put CheckBox with multiple lines and all lines after
fist with smaller font size same as
we have under from home page Menu->Settings->Sound & Display->Silent
mode.
It shows text "Silent mode" on first line and then some more text
(kind of help/current settings) for this option
and still CheckBox itself is aligned in the center of all the lines
(may be on left or right side).
Is that can be done by only one control/widget or group of many
controls/widgets?

I can only think of by using table but it is complex. I tried
android:contentDescription but it did not work. Looks like it is for
accessibility.
Any help will be appreciated.
Thanks,
JP

-- 

2. button placement problem

Hey guys,

I am trying to get a button at bottom of a screen having a list view.
This button is non-scrollable and the list view slips below the button
if it is larger than the size of the button. Could someone please help
me get the right xml properties. Tried layout_gravity and other things
but it doesnt seems to be displaying.

Here is the main.xml file


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<TextView
          android:id="@+id/textViewHello"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
 <Button
android:id="@+id/Button1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="15sp"
android:typeface="monospace"
android:textColor="#ffFFffFF"
android:text="@string/Button1"
</Button>
<Button

android:id="@+id/Button2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:textSize="15sp"
android:typeface="monospace"
android:textColor="#ffFFffFF"
android:text="@string/Button2"
</Button>
<Button

android:id="@+id/Button3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:textSize="15sp"
android:typeface="monospace"
android:textColor="#ffFFffFF"
android:text="@string/Button3"
</Button>
<Button
android:id="@+id/Button4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:textSize="15sp"
android:typeface="monospace"
android:textColor="#ffFFffFF"
android:text="@string/Button4"
</Button>
</LinearLayout>
<ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false"
        />
 <Button android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/Button4"
        android:text="@string/hello"
        android:layout_gravity="bottom"
        android:isScrollContainer="false" />
</LinearLayout>


Here is the list xml file.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=
       "http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
                android:id="@+id/icon"
                android:layout_width="22px"
                android:paddingLeft="2px"
                android:paddingRight="2px"
                android:paddingTop="2px"
                android:layout_height="wrap_content"
                android:src="@drawable/icon"/>

        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
        <TextView
                android:id="@+id/label1"
                android:layout_width="100px"
                android:layout_height="wrap_content"
                android:textSize="10sp"/>
        <TextView
                android:id="@+id/label2"
                android:layout_width="100px"
                android:layout_height="wrap_content"
                android:textSize="10sp"/>


        </LinearLayout>
        <TextView
                android:id="@+id/label3"
                android:layout_width="100px"
                android:layout_height="wrap_content"
                android:layout_marginLeft="40px"
                android:textSize="15sp"
                android:text="hello"
                />
        <ImageView
                android:id="@+id/icon"
                android:layout_width="22px"
                android:paddingLeft="2px"
                android:paddingRight="2px"
                android:paddingTop="2px"
                android:layout_height="wrap_content"
                android:src="@drawable/icon" android:layout_gravity="right"/>



</LinearLayout>

Thank you,
Varun

-- 

3. Undetectable Android Service

4. Goo Market Frustration(s) -- a request to experienced app developers

5. 2.2 apk does not install in 2.1 droid

6. 3D Model Loading Problem

7. javax.sound alternative