first you need to create the following folder for different layout .....
Folder Name layout-ldpi layout-land-ldpi layout-mdpi layout-land-mdpi layout-hdpi layout-land-hdpi layout-xlarge layout-xlarge-land
1 ... Change in AndroidManifest.xml
android:configChanges="orientation|keyboardHidden"
2 .... Create layout_land.xml in the layout folder.
3 .... Create layout_port.xml in the layout folder.
4 ... Create the next method
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { setContentView(R.layout.layout_land); set_all_id(); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { setContentView(R.layout.layout_port); set_all_id(); } }
5 .... Change the OnCreate method (this content only)
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getResources().getConfiguration().orientation == 1) { setContentView(R.layout.layout_port); } if (getResources().getConfiguration().orientation == 2) { setContentView(R.layout.layout_land); } set_all_id(); }
6 ... Create a set_all_id () method to initialize objects of the form
public void set_all_id() {
source share