Yes, there are already a lot of answers available on stack overflow on the same topic, most of them stating the following approach:
Manifest.xml:
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
</activity>
Manually handling config changes:
override fun onConfigurationChanged (newConfig: Configuration) {
super.onConfigurationChanged (newConfig)
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// TODO block 1:
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
// TODO block 2:
}
}
Now, let's say I have a simple Android app with one RelativeLayout that contains a button and a text field(EditView). The complete app has been programmatically designed.
In portrait mode: The text field and button are one below the other as shown,
In landscape mode, I want the text field and button to be adjacent to each other, to do so I'll be changing the x, y, height, width, etc inside the TODO block 2 in above mentioned onConfigurationChanged method.
similarly, to handle changes in the app display size (multi-window, multi-screen flip devices) I need to do something similar. (Right now, I don't know how to handle these changes).
Fow now there are just two views in my relative layout: a button and a text field (EditView), let's say when there are 50-60 views in my activity I need to change the x, y, height, and width for each of the view and for each of the scenarios (screen orientation, app display size, etc).
This seems very tedious to do and maintain for a long time, Is there any other way to handle the configuration changes with less efforts?
Note: My whole application is design programmatically and without jetpack compose.
PS: Android docs also does mention that above way isn't the prefered one
I also went through this link, but didn't seem to be useful for the above scenarios. (correct me if I'm wrong)


use following liberties