我想在大量 View 之间导航,所以我用 PagerTabStrip 实现了 ViewPager。现在我希望能够在不更改 View 的情况下从第一个标题转到最后一个标题,如果您注意到 PlayStore 已经实现的话。
PagerTabStrip 仅转到下一个或上一个标题并更改 View ,因为我有很多 View ,我发现它会惹恼用户。
我找到了 XLPagerTabStrip for iOS ,但我找不到适用于 Android 的。
最佳答案
您可以使用 PagerSlidingTabStrip ,
For a working implementation of this project see the sample/ folder.
Include the library as local library project or add the dependency in your build.gradle.
dependencies { compile 'com.astuetz:pagerslidingtabstrip:1.0.1' }
Include the PagerSlidingTabStrip widget in your layout. This should usually be placed above the ViewPager it represents.
<com.astuetz.PagerSlidingTabStrip android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="48dip" />
In your onCreate method (or onCreateView for a fragment), bind the widget to the ViewPager.
// Initialize the ViewPager and set an adapter ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new TestAdapter(getSupportFragmentManager())); // Bind the tabs to the ViewPager PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); tabs.setViewPager(pager);
(Optional) If you use an OnPageChangeListener with your view pager you should set it in the widget rather than on the pager directly.
// continued from above tabs.setOnPageChangeListener(mPageChangeListener);
关于android - 在不更改 View 的情况下在 PagerTabStrip 标题内导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29161415/