Android学习记录(二十九)-- 旋屏不触发activity oncreate重复加载的方法。

来源:互联网 发布:unity3d 地图制作 编辑:程序博客网 时间:2024/06/06 10:49

先上解决方法:

http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android


android:configChanges="keyboardHidden|orientation|screenSize"

Then within the Activity override the onConfigurationChanged method and call setContentView to force the GUI layout to be re-done in the new orientation.

@Overridepublic void onConfigurationChanged(Configuration newConfig) {  super.onConfigurationChanged(newConfig);  setContentView(R.layout.myLayout);}


setContentView后,所有控件需要重新配置监听事件。(xml写的不需要)

记录一下,以后有代码设置屏幕旋转方式时注意。


0 0
原创粉丝点击