So what are the exact advantages of Fragments in Android 3.0?

后端 未结 1 1024
天涯浪人
天涯浪人 2020-12-24 14:13

Could somebody please explain the exact advantages of using Fragments? In what cases should we use Fragments?

For what I understand, this framework:

相关标签:
1条回答
  • 2020-12-24 14:47

    Is there more to this framework?

    • Animated effects available when dynamically adding and removing fragments from the screen

    • Automatic BACK stack management, so the BACK button can remove dynamically-added fragments before eventually exiting the activity

    • Integration with the action bar for tabs, as a replacement for TabHost

    • Integration with the action bar for "list"-based navigation (really a Spinner in the action bar, toggling between different fragments)

    • Somewhat easier handling of configuration changes courtesy of setRetainInstance(true)

    Also, responding to @Jim Blackler:

    I share your confusion, since it's always been easy to customize Views which seems (to me) to solve all the same problems.

    Everything offered by fragments can, by definition, be done using Views, simply because fragments are built on top of the view framework. However, fragments make more complicated scenarios involving dynamic fragments a bit easier IMHO.

    Moreover, fragments in conjunction with the action bar seem quite likely to be a long-term area of attention for Google, meaning I expect a fair amount of additional work in this area over the next 2-3 releases.

    0 讨论(0)
提交回复
热议问题