我一直在寻找并且很难找到一个明确的例子?我正在尝试了解如何在我的 mainActivity 中作为抽屉项打开的片段中创建一个 viewpager...
这是我的尝试,但我认为我做错了什么,无论是我错误地包含它还是将它放在错误的位置......
public class RandomFragment extends android.app.Fragment {@覆盖public View onCreateView(LayoutInflater inflater, ViewGroup 容器,捆绑保存的InstanceState){查看 rootView = inflater.inflate(R.layout.fragment_random, container, false);返回根视图;}@覆盖public void onViewCreated(View view, Bundle savedInstanceState) {super.onViewCreated(view, savedInstanceState);ViewPager mViewPager = (ViewPager) view.findViewById(R.id.random_pager);mViewPager.setAdapter(new MyAdapter(getChildFragmentManager()));}公共静态类 MyAdapter 扩展 FragmentPagerAdapter {公共 MyAdapter(FragmentManager fm) {超级(调频);}@覆盖公共 int getCount() {返回 4;}@覆盖公共片段getItem(int位置){捆绑参数 = 新捆绑();args.putInt(TextViewFragment.POSITION_KEY, 位置);返回 TextViewFragment.newInstance(args);}}
我用这个希望对你也有帮助:https://github.com/thecodepath/android_guides/wiki/ViewPager-with-FragmentPagerAdapter
所以你可以使用这个:https://github.com/astuetz/PagerSlidingTabStripp>
I have been looking and having a hard time finding a clear cut example? I am trying to understand how to create a viewpager within a fragment that is open as a drawer item from my mainActivity...
This is my attempt but I think I am doing something wrong whether it be that I am including it incorrectly or have it in the wrong spot...
public class RandomFragment extends android.app.Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_random, container, false);
return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ViewPager mViewPager = (ViewPager) view.findViewById(R.id.random_pager);
mViewPager.setAdapter(new MyAdapter(getChildFragmentManager()));
}
public static class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return 4;
}
@Override
public Fragment getItem(int position) {
Bundle args = new Bundle();
args.putInt(TextViewFragment.POSITION_KEY, position);
return TextViewFragment.newInstance(args);
}
}
I use this one hope it help you too : https://github.com/thecodepath/android_guides/wiki/ViewPager-with-FragmentPagerAdapter
So you can use this one: https://github.com/astuetz/PagerSlidingTabStrip
这篇关于如何在片段内实现viewpager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!