1

I wonder how can I display the same design when I turn the view to landscape view can anyone help me with this. I tried this code but it didn't do anything

the manifest

android:configChanges="keyboardHidden|orientation"  

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

@Override
public void setContentView(int layoutResID) 
{
    super.setContentView(layoutResID);
}
ndsmyter
  • 6,535
  • 3
  • 22
  • 37
Poison Sniper
  • 148
  • 2
  • 15
  • 2
    Same design may not fit in other orientation, so you should design a new xml file to give the system a hint saying 'use it when landscape'. You can refer here: http://stackoverflow.com/questions/5407752/android-layout-folders-layout-layout-port-layout-land. – erkangur Jan 14 '12 at 19:05
  • thanks for the fast response :) – Poison Sniper Jan 14 '12 at 19:07

1 Answers1

2

Did you put the android:configChanges flag inside an Activity deceleration in your Manifest?

Try:

<activity android:name="myActivity" android:label="@string/app_name"
    android:configChanges="orientation">
</activity>

If you don't want any layout change when your device rotates, this should suffice, and android will just recalculate and redraw the view again. If you do want the layout to be changed though, you'll need to load a different layout on your onConfigurationChanged function:

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    if (newConfig.orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT)
    {
        setContentView(R.layout.portarit_view);
    }
    else if (newConfig.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE)
    {
        setContentView(R.layout.landscape_view);
    }
}

BTW, you can have a decent preview of how it will look like in your layout xml "Graphical Layout" tab.

ndsmyter
  • 6,535
  • 3
  • 22
  • 37
Rotemmiz
  • 7,933
  • 3
  • 36
  • 36