如何刷新无需重新启动活动在Android RelativeLayout的时候方向更改? [英] How to refresh an Android RelativeLayout when orientation changes without restarting the Activity?

查看:280
本文介绍了如何刷新无需重新启动活动在Android RelativeLayout的时候方向更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android活动与RelativeLayout的,我已经被重新定位上的变化采取了以下方法prevent活动:

I have an Android Activity with a RelativeLayout and I have implemented the following method to prevent the activity from being recreated on change of Orientation:

@Override
public void onConfigurationChanged(Configuration newConfig) {       
    super.onConfigurationChanged(newConfig);

}

我显然不是在做这个事情的方法,但它使用的LinearLayout时,工作完美。但是现在,使用RelativeLayout的,我的布局全部更换为横向时搞砸了。

I am obviously not doing anything in this method, but it worked perfect when using a LinearLayout. Now however, using RelativeLayout, my layout is all messed up when changing to landscape orientation.

什么是有屏幕重绘正确不具有活性调用的OnCreate再次重启?最有效的方式。

What is the most efficient way to have the screen redraw correctly without having the activity restarted again with a call to onCreate?

推荐答案

您有两种方式:

  • 在保留对象在一个配置更改
  • 处理配置改变自己

您已经选择了第二种方式。在这种情况下,你必须重新分配资源的每手而这种做法是不推荐。

You have chosen the second way. In this case you have to reassign every resource by hand and this approach is not recommended.

IMHO最好的方式是在第一通过实施该方法:onRetainNonConfigurationInstance();

IMHO the best way is the first by implementing the method: onRetainNonConfigurationInstance();

这里,了解如何使用它们的完整例子。

Here a complete example on howto use.

注:的onCreate将会再次调用,但你可以调整你的code至prevent长捉迷藏的任务要在配置更改时再次呼吁

Note: the onCreate will be called again but you can adjust your code to prevent long runnning task to be called again during a configuration change

这篇关于如何刷新无需重新启动活动在Android RelativeLayout的时候方向更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆