android - 在不更改 View 的情况下在 PagerTabStrip 标题内导航?

标签 android pagertabstrip

我想在大量 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/

相关文章:

android - 从多选 ListView 返回值

android - PagerTabStrip 未显示在面向 Android 6.X (N) 的应用程序的 ViewPager 中

android - 自定义 PagerTabStrip 如何通过单击禁用切换选项卡 - 不起作用

android - ViewPager 只加载一次 fragment

android - 单击xml中的按钮时如何添加声音

android - Hello World 安卓程序

java - Android如何将纬度经度转换成度数格式

android - 导入 JSON 文件而不覆盖 Firebase 中的现有数据