Question

I just want to change Layout when the device has been rotated. but I've found that onConfigurationChanged() must call onCreate() again using setContentView with separated layout named of *_land.xml

if(getActivity().getWindowManager().getDefaultDisplay().
getRotation() == Surface.ROTATION_0)
view = inflater.inflate(R.layout.fragment_layout, null);
else view = inflater.inflate(R.layout.fragment_layout_land, null);

Project is too big and there are many codes to fix If onCreate again without finish().

I'd like somebody help this.

Thank you.

-> onConfigurationChanged concept is keep layout I think

Was it helpful?

Solution

this is not no more interestes

onConfigurationChanged() cannot be used with layout-land folder's machanism. That's because the callback concept is to keep Layout. So Activity which used the method should Inflate landscape Layout.

OTHER TIPS

Just call at the end of the method setContentView(R.layout.activity_main);

public void onConfigurationChanged(Configuration newConfig) {
    setContentView(R.layout.activity_main);
}

So you can use the folder method as normal

You don't need to call the layout for landscape by your own, it will get called automatically if you follow the android folder structure.Like :

Suppose your layout name is "main.xml", then

Keep one main.xml file in layout folder and one in layout-land folder. so in the case of land scape mode, the system will automatically selects the layout from layout-land folder.

Check this link if you have any doubts.

You simply make a main.xml in layout-land folder (created by you not present by default) in res folder with same name as that of your main.xml in layout folder. But make changes in linear layout tag, i.e. make it horizontal instad of vertical of main.xml which is situated in layout-land folder.

After all this you simply call SetContentView(R.layout.main);. And see the magic, your application will work. Also make changes in Android Manifest file, i.e. in your actvity tag make comment android:screenOrientation="portrait" line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top