Use case code of Android nested fragment

preface

The previous article introduced activitygroup. Many people asked about nested use. The same requirement also exists in fragment. Fortunately, this feature is supported in the latest Android support package! We will skip the introduction of fragment here. It should be noted that the tag activity has been marked as deprecated.

text

1、 Prepare

For an introduction to the latest Android compatibility package, see the official website. You can find the latest version in extras / Android / support / V13 / android-support-v13.jar in the Android SDK directory. Note that it is updated with Android 4.2.

For an introduction to nested fragments, please refer to the official website.

2、 Screenshot

3、 Code

FragmentNestActivity.java

Code Description:

The key here is the support of the method getchildfragmentmanager. The use of fragment as a nested inner class is also demonstrated here.

nested_ fragments.xml

viewpager_ fragments.xml

Code Description:

be careful! In practice, it is found that viewpager cannot be used as a top-level container, otherwise an error will be reported.

4、 Explain

This is a typical example of nested fragments. The outermost layer uses FrameLayout to switch several major modules, and the internal layer uses viewpager to switch sub modules. It is very practical.

end

Consider updating and translating the support package and revision 11. We strongly recommend that you upgrade to the latest compatible package.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>