Android的碎片VS复合控件 [英] Android fragments vs compound controls

查看:126
本文介绍了Android的碎片VS复合控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要的Andr​​oid来代替复合控件3.0片段?你可以创建一个视图继承或复合控制一次,并用它无处不在。

Why should Android 3.0 fragments be used instead of compound controls? One can create a View inheritor or compound control once and use it everywhere.

我读过<一个href="http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html">http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html但并没有找到答案。

I've read http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html but did not find the answer.

推荐答案

不同的是,片段具有其自己的生命周期(的onPause,的onCreate,ONSTART ...)。通过具有生命周期,片段可以独立对事件作出响应,通过的onSaveInstanceState保存其状态,并带回(来电或当用户单击后退按钮后恢复时,即如)。生命周期总结片段文件中:

The difference is that fragments have a life cycle (onPause, onCreate, onStart...) of their own. By having a life cycle, fragments can respond independently to events, save their state through onSaveInstanceState, and be brought back (i.e. such as when resuming after an incoming call or when the user clicks the back button). The life cycle is summarized in the fragment documentation:

<一个href="http://developer.android.com/guide/topics/fundamentals/fragments.html#Lifecycle">http://developer.android.com/guide/topics/fundamentals/fragments.html#Lifecycle

您可以随时换一个片段或活动围绕一个复合视图,因此仅仅觉得片段作为容器的化合物的意见,让他们独立的生命周期。

You can always wrap a fragment or activity around a compound view, so just think of fragments as containers to your compound views that give them an independent life cycle.

这篇关于Android的碎片VS复合控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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