2

I followed the android developrs tutorial to create a simple tab layout. Everything is fine with the tutorial, I got the tab layout working.

In default portrait mode, the tabs are located on top of screen, but when change to landscape mode, the tabs on the top makes the screen looks odd, so, I would like to locate the tabs on the left side of the screen vertically when the emulator change to landscape mode.

I am not sure What is the correct way to do it? I mean the correct way to define different tabs layout for portrait mode and landscape mode. Anybody can give some suggestions?

Leem
  • 17,220
  • 36
  • 109
  • 159

3 Answers3

0

On your AndroidMainfest.xml add

<activity android:name=".MyActivity"
    android:configChanges="orientation" >
</activity>

And when application changes orientation, override the method on your MyActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            // do what you want
    }
    else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            // do what the other thing you want
    }

}

This from: http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

Tip: When orientation changes, the Activity is restarted if you don't add android:configChanges.

cristhoper
  • 141
  • 5
0

Create two layout files one for portrait and one for landscape. place these layout-port and layout-land respectively. You'll have to handle screen orientation if u want to save the state of the screen

pradeep
  • 3,005
  • 12
  • 42
  • 65
0

You need to set up 2 different layouts for the activity, one in portrait ("normal") mode, one in landscape mode. This implies to not use TabActivity.

Put landscape_tab.xml in layout-land folder inside res folder (res/layout-land)

Put portrait_tab.xml in layout-port folder inside res folder (res/layout-port)

OfCourse you have to create layout-land and layout-port folder in res directory manually

Your Solution is here android:orientation="vertical" does not work for TabWidget

cheers :)

Community
  • 1
  • 1
Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104