Android - How to have Mixed Orientation Tabs? (some tabs portrait, others landscape)

北城余情 提交于 2019-12-12 17:53:04

问题


I have created an app with multiple tabs, each with its own layout. I have shut down response to the accelerometer to keep the app in portrait mode (android:screenOrientation="portrait").

Two of the tabs are designed in portrait mode, and one tab is designed in landscape mode. I need to take advantage of the fact that the screen is wider than it is high in landscape to display a mini spreadsheet.

Here is my question: How do I orient one of the tabs to landscape, while leaving the other two in portrait mode?

Any suggestions?


回答1:


To programmatically change orientation use setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); or setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);. In this case each tab click event could be tied to its relevant orientation

source: http://russenreaktor.wordpress.com/2010/01/03/solved-set-screen-orientation-programmatically/




回答2:


I found a solution outside of the tab-set. The following link discusses multiple solutions for displaying Vertical text:

Vertical (rotated) label in Android

I went with "CustomTextView" by PocketMagic which can be found here: http://www.pocketmagic.net/?p=1625

With the ability to display vertical text, I can keep the entire tab-set locked in Portrait mode.

Thanks for the suggestions everyone.

-cc




回答3:


not sure if you got an answer yet, but I've been searching for 30 mins and found a solution to a similar problem. Hope this helps.

I'm using tabhost and want 3 of 4 tabs to be able to rotate and 1 tab set to portrait mode only. Previously (before applying this fix) the 3 tabs would rotate until the fixed portrait tab was selected, then they were all stuck in portrait mode.

I had to set the other tabs to use the orientation of the USER to remedy this. i.e. added a setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER); in the onResume of the other 3 tabs and it now works exactly as I had intended. 3 tabs will now rotate based on the user's orientation of the device, and 1 tab is fixed portrait. :)



来源:https://stackoverflow.com/questions/6701000/android-how-to-have-mixed-orientation-tabs-some-tabs-portrait-others-landsc

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