I'm using ActionBar
of AppCompact
with tabs and ViewPager
.
How can I implement moving (with the fragment) tabs indicator like in Onavo app?
I tried to use PagerTitleStrip
but didn't succeed.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There is a library called "PagerSlidingTabStrip" that does exactly what you want: https://github.com/astuetz/PagerSlidingTabStrip
Interactive paging indicator widget, compatible with the ViewPager from the Android Support Library.
Usage
Include the PagerSlidingTabStrip widget in your view. This should usually be placed adjacent to the ViewPager it represents.
<com.astuetz.viewpager.extensions.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.
// Set the pager with an adapter
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new TestAdapter(getSupportFragmentManager()));
// Bind the widget to the adapter
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);