[英]How to change orientation to portrait in Fragment Class - Android
我的應用程序處於風景模式..我正在嘗試更改肖像視圖中的片段。
使用以下代碼從橫向旋轉到縱向..
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
但是片段“ onCreate”和“ onCreateView”兩次調用..
有人可以在Fragment類中實現Portrait View的建議嗎? 或關於如何避免兩次調用onCreateView的建議?
您的活動應在清單文件中添加,
“機器人:configChanges =” keyboardHidden |方向|屏幕尺寸”
例如,
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
具體來說,您應該在Android清單文件中添加“ screenSize”。 這樣您的片段“ onCreate”和“ onCreateView”將不會被調用兩次。
覆蓋setRetainInstance。 這應該可以解決您的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.