我必须使用TabHost
代替ActionBarTabs
为了使它们可以滚动,我已经包裹了我的TabWidget
in a HorizontalScrollView
,但是HorizontalScrollView
不按照以下方式自行滚动ViewPager
。我尝试过以几种不同的方式使用scrollTo和fullScroll,但它没有改变任何东西。我需要做什么才能使其正常工作?
<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);
}
当你调用时水平滚动视图会改变.refreshDrawableState()
拨打电话后.scrollTo(x,y)
方法。
另一件需要注意的事情是.scrollTo(x,y)
滚动使得x
位于屏幕的左侧。您可能需要对选项卡的坐标和水平滚动视图的宽度进行一些数学计算,以正确定位内容。你不能打电话.scrollTo(position,0)
并让它按照您想要的方式工作(除非您的选项卡是 1 像素宽)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)