简体   繁体   English

ViewPager不适用于所有活动片段

[英]ViewPager not for all activity fragments

So I saw on an android developer site the example implementation of a ViewPager. 因此,我在android开发人员网站上看到了ViewPager的示例实现。 I saw that ViewPager must be set in an activity class. 我看到必须在活动类中设置ViewPager。 My application has only one Actvity with about 15 Fragments. 我的应用程序只有一个Actvity,带有大约15个片段。 The thing I want to do is to use ViewPager only for 3 Fragments, for example: 我想做的是仅对3个片段使用ViewPager,例如:

  • I go to Fragment 5 我去片段5
  • When I click back I go to Fragment 1 (this is yet implemented) 当我单击返回时,我转到片段1(尚未实现)
  • When I swipe in Fragment 5 from left to right I go to Fragment 4 当我从左向右滑动片段5时,我会转到片段4
  • When I swipe in Fragment 5 from right to left I go to Fragment 6 当我从右向左滑动片段5时,我进入片段6
  • When I swipe in the Fragment4/Fragment6 I go back to Fragment 5 当我在Fragment4 / Fragment6中滑动时,我回到Fragment 5
  • When I swipe in the rest of Fragments, nothing happens 当我在其余片段上滑动时,什么也没有发生

Is this even possible with only one Activity containing these all fragments? 仅包含所有这些片段的一个活动,甚至可能实现吗? I will be grateful for any kind of hints. 我将不胜感激。

PS: If that is gonna be helpful answering my question, this is how I switch between fragments now: PS:如果那将有助于回答我的问题,这就是我现在如何在片段之间切换:

MealInfoFragment fragment = new MealInfoFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(MainActivity.currentFragment);
fragmentTransaction.commit();

仅作记录,我通过在包含其他3个片段的片段中创建viewpager来做到这一点!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM