I need to use TabHost instead of ActionBarTabs and make them scrollable. I wrapped my TabWidget in a HorizontalScrollView , but the HorizontalScrollView does not scroll in according to the ViewPager . I tried using scrollTo and fullScroll in several ways, but that doesn't change anything. What do I need to do for this to work correctly?
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <HorizontalScrollView android:id="@id/horizontalScrollView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:fillViewport="true" android:scrollbars="@null" > <TabWidget android:id="@android:id/tabs" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" /> </HorizontalScrollView> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0" /> <android.support.v4.view.ViewPager android:id="@id/viewPager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </LinearLayout>
@Override public void onTabChanged(String tabId) { int position = mTabHost.getCurrentTab(); mViewPager.setCurrentItem(position); mHorizontalScrollView.scrollTo(position, 0); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { mHorizontalScrollView.scrollTo(position, 0); }
source share