One of our views has a ScrollView
as its root layout. When the device is rotated and onConfigurationChanged()
is called, we'd like to be able to get the ScrollView
's new width/height. Our code looks like this:
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.d(TAG, "Width: '" + findViewById(R.id.scrollview).getWidth() + "'");
Log.d(TAG, "Height: '" + findViewById(R.id.scrollview).getHeight() + "'");
super.onConfigurationChanged(newConfig);
Log.d(TAG, "Width: '" + findViewById(R.id.scrollview).getWidth() + "'");
Log.d(TAG, "Height: '" + findViewById(R.id.scrollview).getHeight() + "'");
}
The relevant section of our AndroidManifest.xml looks like this:
<activity android:name=".SomeActivity"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
And finally, the relevant portion of our layout looks like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<LinearLayout android:id="@+id/container"
android:orientation="vertical"
android:layout_height="fill_parent"
android:minHeight="200dip"
android:layout_width="fill_parent"
>
On our Droid, we expected to see the ScrollView's width go to 854 when switched into landscape, and to 480 when switched back to portrait (and the height do the equivalent switch, minus the menu bar). However, we're seeing the opposite. Here's our LogCat:
// Switching to landscape:
03-26 11:26:16.490: DEBUG/ourtag(17245): Width: '480' // Before super
03-26 11:26:16.490: DEBUG/ourtag(17245): Height: '778' // Before super
03-26 11:26:16.529: DEBUG/ourtag(17245): Width: '480' // After super
03-26 11:26:16.536: DEBUG/ourtag(17245): Height: '778' // After super
// Switching to portrait:
03-26 11:26:28.724: DEBUG/ourtag(17245): Width: '854' // Before super
03-26 11:26:28.740: DEBUG/ourtag(17245): Height: '404' // Before super
03-26 11:26:28.740: DEBUG/ourtag(17245): Width: '854' // After super
03-26 11:26:28.740: DEBUG/ourtag(17245): Height: '404' // After super
Clearly, we're getting the portrait dimensions when we switch to landscape, and the landscape dimensions when we switch to portrait. Is there something we're doing wrong? We could get hacky and solve this, but I feel like there's a simple solution that we're missing.