简体   繁体   English

更改方向更改片段-Android

[英]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. 根据屏幕的方向,我必须在一个活动中显示3个片段,A,B和C。 In the portrait mode i want to display A and B, in the landscape mode i want to display B and C. 在纵向模式下,我想显示A和B,在横向模式下,我想显示B和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 ? 知道当旋转数位板时,活动会调用on Create方法时,如何将片段动态添加到活动中的最佳实践是什么?

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 在您的情况下,您可以在onCreate()检查显示方向,或者,如果未从代码中添加片段,请在layout-land区域中使用相同的名称创建不同的布局文件,并直接在XML中引用不同的片段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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