Cameron McBride
Cameron McBride

Reputation: 6799

Display one view in portrait while another is in landscape?

I have an activity that per our requirements has to be locked into landscape orientation. However when the user holds the device in portrait we display a view on top of it. Up until now it has just been an image so I have rotated the image and I display it. Really the image is also being displayed in landscape but since I have rotated it, it appears like it is in portrait.

Now I need to complicate this by having a more complex view with layouts being displayed (layouts, textviews, buttons, etc) instead of just an image. The same "rotation" doesn't seem to work because stuff is displayed off of the screen. What is the recommended solution to show one view in portrait while the view behind it is locked in landscape?

Upvotes: 0

Views: 125

Answers (1)

Budius
Budius

Reputation: 39846

edit:

if the idea is to literally have the view underneath to show rotated 90% while the top view is in "normal" view, you could possibly call setRotation method, available since API 11

 view.setRotation(90);

edit: below is my old answer, please see above my updated question

Do not lock the view in landscape. Instead use the layout/ and layout-land/ folders to place appropriate views. For example:

layout/main.xml

<FrameLayout
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”>

    <include layout="@layout/main_content"/>

</FrameLayout>

layout-land/main.xml

<FrameLayout
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”>

    <include layout="@layout/main_content"/>

    <FrameLayout
        android:layout_width=”match_parent”
        android:layout_height=”match_parent”
        android:padding="144dp"
        background="#4000">

         <include layout="@layout/top_content"/>

    </FrameLayout>
</FrameLayout>

Upvotes: 0

Related Questions