Android: FragmentActivity in FragmentActivity (Scrollview in Navigationbar)

只谈情不闲聊 提交于 2019-12-08 05:42:11

问题


I have a FragmentActivity which can swipe through several fragments via ViewPager and a FragmentActivity which hosts an ActionBar for navigation.

Now I want to nest the FragmentActivity with the ViewPager in the first fragment of the other FragmentActivity which hosts the ActionBar.

In other words I like to have an ActionBar navigation and in it's first Tab I'd like to have swipeable fragments.

My problem is how to nest one FragmentActivity in another FragmentActivity. Both work on their own but I don't get them to work together.


回答1:


Swipe Gesture applied at Fragment level along with ViewPager with it's default swipe disabled

You can write your own touch interceptor for the fragments inside your view-pager.

However on a second opinion, please see my moqup in the question:

You can have several ViewGroup container preferably FrameLayout, where on each you can add or remove fragments using transactions. The container of the Navigation Panel is different than where the ViewPager is showing:

Keep this ViewPager in a separate fragment that spawns in yet another FrameLayout. in ViewPager here you should not use the FragmentPageAdapter, but a regular PagerAdapter (avoid nesting of fragments). Hence the ViewPager is a parent container for the Views, and not Fragments where they are shown.

The target of the navigation drawer (on item click) will be this second FrameLayout. Keep it simple!!

Similarly you can have a ViewPager inside a first tab of Tab based ViewPager with this new found information.



来源:https://stackoverflow.com/questions/11761454/android-fragmentactivity-in-fragmentactivity-scrollview-in-navigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!