Android: Landscape Child Activity in a Portrait Ta

2019-08-02 14:56发布

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.

3条回答
Juvenile、少年°
2楼-- · 2019-08-02 15:10

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-08-02 15:17

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!

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-08-02 15:20

Use this in AndroidManifest :

<activity android:name=".YourClass" android:screenOrientation="portrait"></activity>
查看更多
登录 后发表回答