我有在地方使用TabHost
的ActionBarTabs
并使其滚动能够我包裹着我的TabWidget
在HorizontalScrollView
,但HorizontalScrollView
不滚动本身根据ViewPager
。我尝试过使用scrollTo和fullScroll几种不同的方式,但它不会改变任何东西。我需要做些什么才能正确地工作?TabWidget包裹在HorizontalScrollView不ViewPager
<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()'。自从我发布后,我已经了解了左边的'x'坐标。 'scrollBy()'似乎比'scrollTo()'更好。感谢您的提示。 – adneal 2012-03-13 00:29:44