簡體   English   中英

如何在Android中更改片段的方向?

[英]How to change the Orientation for fragments in Android?

我已經設法在我的活動中更改了片段的方向。 旋轉設備時,方向會發生變化。

現在,當我點擊片段中的按鈕時,我想要相同的功能。 即當我點擊肖像布局和簽證上的按鈕時,我想從縱向模式更改為LandScape模式。

我用了

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

分別。

但這使自動旋轉功能停止工作。 我該如何解決這個問題?

當你需要自動旋轉時,使用getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

請試試這個

             <activity 
              android:name="<class name with package>"
                   android:label="@string/app_name"
                 android:theme="@android:style/Theme.NoTitleBar"
                 android:configChanges="orientation|keyboardHidden"
                android:screenOrientation="portrait">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM