片段的片段内 [英] Fragment inside a fragment
问题描述
是否有可能把一个片段在Android中的片段里面?想想看:你说,我实现了使用片段和ViewPager swipeable标签。现在,里面每个swipeable片段,我要实现另一个片段 - 有点像嵌套在另一个片段里的片段。但是一个片段需要被附连到一个活动类。那么,如何才能做到这一点?
是否有可能把一个片段在Android中的片段里面?
使用片段支持Android包的反向移植,是的。此外,在Android 4.2及更高版本(API等级17+)支持嵌套的片段原生片段。然而,从API级别11-16原生片段没有。
说,我实现了使用片段和ViewPager swipeable标签。现在,里面每个swipeable片段,我要实现另一个片段 - 有点像嵌套在另一个片段里的片段。但是一个片段需要被附连到一个活动类。那么,如何才能做到这一点?
这证明其碎片在<$示例项目C $ C> ViewPager 和具有 ViewPager
本身是一个片段。关键是, FragmentManager
你提供给你的 FragmentPagerAdapter
的必须的是子片段经理外片段(即 getChildFragmentManager()
)。
Is it possible to put a fragment inside a fragment in Android? Consider this: Say, I implement swipeable tabs using Fragment and ViewPager. Now, inside each of these swipeable fragments, I want to implement another fragment - kind of like a fragment nested inside another fragment. But a fragment needs to be attached to an Activity class. So how can this be done?
Is it possible to put a fragment inside a fragment in Android?
Using the Android Support package's backport of fragments, yes. Also, native fragments on Android 4.2 and higher (API Level 17+) support nested fragments. However, native fragments from API Level 11-16 do not.
Say, I implement swipeable tabs using Fragment and ViewPager. Now, inside each of these swipeable fragments, I want to implement another fragment - kind of like a fragment nested inside another fragment. But a fragment needs to be attached to an Activity class. So how can this be done?
This sample project demonstrates having fragments in a ViewPager
and having the ViewPager
itself be in a fragment. The key is that the FragmentManager
you supply to your FragmentPagerAdapter
must be the child fragment manager of the outer fragment (i.e., getChildFragmentManager()
).
这篇关于片段的片段内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!