简体   繁体   中英

change fragment on orientation change - Android

I have 3 fragments, A, B and C that i have to display in a activity depending on the orientation of the screen. In the portrait mode i want to display A and B, in the landscape mode i want to display B and C.

What is the best practice to add dynamically my fragments to the activity knowing that when the tablet is rotated, the activity calls the on Create method ?

It depends on what these fragments are expected to do and other app related factors. In your case you can check display orientation in onCreate() or, if fragments are not added from code, create different layout file in layout-land with the same name and reference different fragments directly in XML

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM