Open ChenShiChao opened 8 years ago
Demo中,如果把ViewPage嵌套在Fragment中,TabPageIndicator的name和指示都不显示;
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.activity_view_pager, null); int startIndex = 0; mCatTabPageIndicator = (TabPageIndicator) view.findViewById(R.id.view_pager_tab_indicator); mFragmentViewPager = (ViewPager) view.findViewById(R.id.view_pager_view_pager); ArrayList<ViewPagerFragment> list = new ArrayList<ViewPagerFragment>(); for (int i = 1; i <= 8; i++) { list.add(ViewPagerFragment.create(i)); } mPagerAdapter = new FragmentViewPagerAdapter(getChildFragmentManager(), list); mFragmentViewPager.setAdapter(mPagerAdapter); mCatTabPageIndicator.setViewHolderCreator(new TabPageIndicator.ViewHolderCreator() { @Override public TabPageIndicator.ViewHolderBase createViewHolder() { return new HomeCatItemViewHolder(); } }); mCatTabPageIndicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int i) { switchTo(i); } }); mCatTabPageIndicator.setViewPager(mFragmentViewPager); mPtrFrame = (PtrClassicFrameLayout) view .findViewById(R.id.view_pager_ptr_frame); mPtrFrame.disableWhenHorizontalMove(true); mPtrFrame.setPtrHandler(new PtrHandler() { @Override public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { return mPagerAdapter.checkCanDoRefresh(); } @Override public void onRefreshBegin(PtrFrameLayout frame) { mPagerAdapter.updateData(); } }); mFragmentViewPager.setCurrentItem(startIndex); return view; }
可以调试看看TabPageIndicator的updateTab方法,找找原因
Demo中,如果把ViewPage嵌套在Fragment中,TabPageIndicator的name和指示都不显示;