Android: Landscape Child Activity in a Portrait Tab Activity

∥☆過路亽.° 提交于 2019-12-24 07:27:18

问题


I have a tab activity that has three child activities, A, B and C. Child activities A and B are to follow the orientation of the tab activity. i.e. if the tab activity is in portrait so should A and B, if the tag activity is landscape so should A and B.

Child activity C should always be in landscape orientation regardless of the tab activity orientation (preferably following android:screenOrientation="sensorLandscape"). Is this possible?

I have tried using android:screenOrientation="sensorLandscape" for C in the manifest which doesn't work. The best I can manage is to use the following in C (in onResume())

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

and for A and B I use (also in onResume())

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

But this flips the entire tab which is not the effect I'm looking for.


回答1:


I'm a newbie and all I can say is that the tab layout is very picky about what you do in it. try making it all landscape, then changing the orientarion of the two a/b tabs after C is working... good luck!




回答2:


Use this in AndroidManifest :

<activity android:name=".YourClass" android:screenOrientation="portrait"></activity>



回答3:


I faced the same problem. Dont know if it is a good solution, but the workaround I found is as follows: Put this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); before the setContentView() of onCreate() method of Activity C. And put this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); before the setContentView() of onCreate() method of other two Activities (A and B).

Any other elegant solution is highly appreciated.



来源:https://stackoverflow.com/questions/6615548/android-landscape-child-activity-in-a-portrait-tab-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!