onConfigurationChanged-で示す最初のレイアウト
-
25-09-2019 - |
質問
い活動を取り扱うになります。今はこんなものがあるようで変更 レイアウト。また、onConfigurationChangedコールバック関数で設定を再度レイアウト、いまのレイアウト(土)いますが、それはまだ不明 最初のレイアウトのための画像ビューがレイアウト(名称)を設置res/ レイアウトおよびres/レイアウト-土地)
を削除するとandroid:configChanges="方位"を動作させることができるべきでıを取り扱う必要がありonConfigurationChanged.どうしたらよいですか??
解決
あなたはmain.xml
に/res/layout
であなたの肖像画のレイアウトmain.xml
とあなたのランドスケープレイアウト/res/layout-land
を持っており、このようなあなたのonConfigurationChanged()
のルックス場合:
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
...
...
...
}
そして、あなたのマニフェストにあなたがandroid:configChanges="keyboardHidden|orientation"
それから、罰金を動作するはずです。これは、あなたがやっているのですか?
他のヒント
// In your activity code.
int mCurrentOrientation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mfo_offers);
........
mCurrentOrientation = getCurrentOrientation();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// You may handle different configuration changes in your activity which configured in your mainfest.xml, you only need to recreate layout when orientation changes.
if(mCurrentOrientation != newConfig.orientation) {
recreate(); // This recreate the activity if you can properly restore your activity state.
}
......
}
ここでを参照してくださいActivity.recreate():ます。http:// developer.android.com/reference/android/app/Activity.html#recreate()の
所属していません StackOverflow