Partial landscape orientation, partial portrait orientation for single activity
I want to have some buttons/textviews in my Activity displayed in portrait orientation, while the rest of the activity is fixed in landscape orientation.
Is it possible to have some of the views (or layouts) in your activity be displayed in landscape orientation, and some displayed in portrait orientation? Maybe I can have two activities displayed as one activity if that's possible? That way I can define the orientation per activity.
-Edit June 24 '11 11:45am:
I'm sorry, I should have invested more time in explaining my question better. I want one single activity to always have some views fixed in landscape screen orientation (not layout orientation), and some always fixed in portrait screen orientntation (again, not layout orientation). I understand that a layout orientation controls whether the views are added vertically or horizontally (vertically being stacked top to bottom, and horizontally being stacked from left to right) but if the screen orientation of the activity landscape, the will still all be displayed in landscape orientation, and vice-versa fo开发者_如何转开发r portrait. That's not what I'm asking. So essentially some of my views will show up in landscape, and the rest in portarit meaning their text/shape will be "side-ways" or "perpendicular" in relation to the landscape views.
So far I've tried putting a rotate 90degree animation on the views I wanted in portrait. That kind of worked, but my views happens to be buttons and I've found through experimentation and research on stackoverflow that rotation only affects the drawing, not the actual area the activity still thinks where the view was originally placed. So that messes with the clickable area of the button that is rotated, and makes things act funny. I'm sure there's gotta be a better way.
I don't want to use fragments since I want to be able to support older Android versions. And I'm not sure if fragments even support this anyway. I also don't want to use two activities, one being landscape and transparent and stacked on top of the other one which is portrait, since that will make things unnecessarily complex.
I guess what I'm asking is going to involve some advanced manipulation or tricks, and is not very common. I've done a lot of research on this and couldn't find anything. But I think if we can figure this out, this could be a useful method for someone else looking to do this (can't really think of many reasons they would want to but I'm sure there are).
Here are some images I put together to illustrate my point. Looks like I'm too new to the forum to embed the images in my question. Sorry! You'll have to follow the links.
1) This is what I have currently, a vertically oriented LinearLayout has two sub-LinearLayouts. The first sub-LinearLayout has a bunch of TextViews. The second sub-LinearLayout has a bunch of buttons, and this is the one that I want oriented in portrait mode: !(http://synappze.com/development/activity-partial-screen-orientation-illustration-1.jpg)
2) If I orient the main LinearLayout horizontally, the two sub-LinearLayouts would show up like below. But I want the one on the right with the buttons to be displayed in portrait: http://synappze.com/development/activity-partial-screen-orientation-illustration-2.jpg
3) This is what I want. Notice the buttons on the right are displayed in portrait orientation, whereas the TextViews are still in landscape orientation: http://synappze.com/development/activity-partial-screen-orientation-illustration-3.jpg
You could keep the part you want displayed in portrait and the part you want as fixed landscape in two different xml layout files. Then, in your onCreate()
method, programmatically determine the orientation of the phone and include the two files in your layout accordingly. Sorry for the quick answer... I'm off to work now. Let me know if you have questions about this, I can answer when I get there.
For each activity in your manifest file you can add orientation attribute and you can set it to either landscape or portrait
example :
you can do this for all your activities defined in manifest
精彩评论