[关闭]
@kmfish 2016-01-16T15:20:03.000000Z 字数 1634 阅读 1483

Why use fragment?


针对这个问题,在网上搜索了下,有以下一些看法:

1、fragments are more reusable than custom views.

作者认为,fragment能够封装单靠view无法处理的事。自定义控件无法处理跨activity交互等事件,还是需要靠activity来完成,这会增加custom views 和activity的耦合。不利于复用。而fragment可以封装更多的东西,包括AsyncTask,file and database access等。

2、the main reason to use Fragments are for the backstack and lifecycle
features. Otherwise, custom views are more light weight, simpler to
implement, and have the advantage that they can be nested.
see here

主要原因是fragment提供了backstack支持界面状态的回退,以及生命周期特性。(在SDK 17 以后fragment也支持嵌套了)

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注