2

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?

codingCat
  • 2,396
  • 4
  • 21
  • 27

3 Answers3

3

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/

Ashterothi
  • 3,282
  • 1
  • 21
  • 35
  • This will effect the tabset as a whole, won't it? For this application I need the tabs to stay at the top (in portrait mode) and not shit to the right (landscape) when the phone is rotated. Is there a way to only rotate the layout inside of a tab, without rotating the entire screen? – codingCat Jul 14 '11 at 23:30
  • If you have a method for each tab forcing it to the orientation you want, it will always have the correct orientation for the actively selected Tab. – Ashterothi Jul 14 '11 at 23:33
  • No. This had the predicted result. The frame set rotated alone with everything else placing the tabs at the top of the screen in landscape mode. What I need is the ability to rotate the _Contents_ of a single tab to landscape mode, or the ability to _Lock_ the tabs in place at the top of the portrait oriented screen. – codingCat Jul 16 '11 at 00:45
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

Community
  • 1
  • 1
codingCat
  • 2,396
  • 4
  • 21
  • 27
1

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. :)

Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141