Handling Orientation Changes Android
Solution 1:
It depends when that code is run, but you generally don't need to do anything special.
When Android detects an orientation change, the system will re-create your Activity and it will get a chance to go through onCreate and re-layout and re-render everything according to the new configuration.
Using android android:configChanges
should be used with care and not be the first option you think of, since the system will do a better job at selecting appropriate resources for you after a configuration change (and you'll have to handle that code path for other forms of configuration change anyways).
See: http://developer.android.com/guide/topics/resources/runtime-changes.html
Solution 2:
Yes. One way is to put android:configChanges="orientation|keyboardHidden"
on your <activity>
in the AndroidManifest.xml file, and then override onConfigurationChanged
to detect the orientation change.
Solution 3:
If you want to persist the number of images displayed in one row you can use the GridView. In this way you can control the number of columns per line.
<GridViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:isScrollContainer="true"android:numColumns="3"android:verticalSpacing="10dp"android:horizontalSpacing="10dp"
/>
Post a Comment for "Handling Orientation Changes Android"