我想停止活动刷新,当我移动到肖像情绪到风景情绪时,我也想加载文件布局-土地,当它移动到肖像到风景情绪时,没有任何刷新活动。
我使用<activity android:name=".Login" android:configChanges="orientation|screenSize">
但是,在这种方法中,当我移动到肖像到风景的情绪,它不加载文件从布局-土地文件夹。我应该为此做些什么?请谁来帮帮我。
发布于 2012-10-09 15:27:06
在onConfigurationChanged()中调用方法setContentView(R.layout.main)
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
///in case you have some EditTexts , save their input before setting the new layout.
emailForConfigChanges = emailTextBox.getText().toString().trim();
passwordForConfigChanges = passwordTextBox.getText().toString().trim();
setContentView(R.layout.main);
//Now set the values back to the EditTexts .
}您只需将此方法添加到您的活动中,因为如果您在清单中声明了" orientation“,则它会处理所有的方向更改。
EDIT :,如果EditTexts在旋转时丢失了它们的值,则在onConfigurationChanged()中调用setContentView()之前获取它们的值。请参见上面的编辑。
发布于 2012-10-09 15:31:23
我只通过添加android:configChanges="keyboardHidden|orientation"来处理这个问题
希望这能对你有所帮助。
https://stackoverflow.com/questions/12794867
复制相似问题