4

I've created a custom tab activity which has two different drawables for portrait and landscape orientation. The icons for portrait screen is under drawable-hdpi while the images for landscape is under drawable-land-hdpi. As of now, I put config change in the manifest to preserve the dialog's visibility.

android:configChanges="orientation"

Whenever the dialog is shown and user changes the orientation from portrait to landscape, the dialog still shows but the images it uses in tab activity is for portrait mode. That's why the layout for doesn't look right since it didn't use the drawables for landscape. Could someone help me with this? Thanks.

iamtheexp01
  • 3,446
  • 9
  • 35
  • 35

3 Answers3

3

If you use android:configChanges="orientation" then Android doesn't re-create the activity when the orientation is changed. If you don't want the dialog to be dismissed, just use the Activity.showDialog() method. And if you still want to use android:configChanges="orientation" then you have to change drawables manually in the Activity.onConfigurationChanged() method.

Michael
  • 53,859
  • 22
  • 133
  • 139
  • I don't want to set the layout manually in onConfigurationChanged because I think there would be a better alternative. If I use showDialog(), would it ensure that even though I change the orientation, it wouldn't dismiss? – iamtheexp01 May 06 '11 at 08:39
  • When you use the `Activity.showDialog()` method, then the activity manages this dialog: dismisses it and re-creates. – Michael May 06 '11 at 08:46
  • Indeed but my problem is the layout, it didn't use the landscape layout of tab. Could I combine using the android:configChanges="orientation", creating /res/layout-land/main.xml and /drawable-land-hdpi? – iamtheexp01 May 06 '11 at 11:08
  • You don't need to change the layout file. Android will use `/res/layout-land/main.xml`. You have to change only resources which need to be displayed in other way. You can read about it here: http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch. – Michael May 06 '11 at 11:52
0

Add like this in your activity tag in application manifest.xml

<activity android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenSize" android:name=".your.package"/>
Deepak
  • 61
  • 1
  • 4
0

You can perform custom layout implementation by detecting the orientation mode as below:

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

    if(config.orientation == Configuration.ORIENTATION_LANDSCAPE)
        Log.i("orientation", "Orientation changed to: Landscape");
    else
        Log.i("orientation", "Orientation changed to: Portrait");
}
i18n
  • 130
  • 5