Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get NEW width/height of root layout in onConfigurationChanged?
    text
    copied!<p>One of our views has a <code>ScrollView</code> as its root layout. When the device is rotated and <code>onConfigurationChanged()</code> is called, we'd like to be able to get the <code>ScrollView</code>'s new width/height. Our code looks like this:</p> <pre><code>@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() + "'"); } </code></pre> <p>The relevant section of our AndroidManifest.xml looks like this:</p> <pre><code>&lt;activity android:name=".SomeActivity" android:configChanges="keyboardHidden|orientation"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre> <p>And finally, the relevant portion of our layout looks like this:</p> <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollview" android:layout_height="fill_parent" android:layout_width="fill_parent" &gt; &lt;LinearLayout android:id="@+id/container" android:orientation="vertical" android:layout_height="fill_parent" android:minHeight="200dip" android:layout_width="fill_parent" &gt; </code></pre> <p>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:</p> <pre><code>// 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 </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload