包含在Horizo​​ntalScrollView中的TabWidget不会使用ViewPager滚动

adn*_*eal 4 java android horizontalscrollview android-viewpager

我在使用TabHost中发生的ActionBarTabs,并让他们滚动能够我包裹着我TabWidgetHorizontalScrollView,但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>
Run Code Online (Sandbox Code Playgroud)

        @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);
    }
Run Code Online (Sandbox Code Playgroud)

rom*_*ows 5

.refreshDrawableState()调用.scrollTo(x,y)方法后调用时,水平滚动视图将发生变化.

需要注意的另一件事是.scrollTo(x,y)卷轴,x它位于屏幕的左侧.您可能需要使用选项卡的坐标和水平滚动视图的宽度进行一些计算,以正确定位.您不能.scrollTo(position,0)按照自己喜欢的方式调用它(除非您的标签宽度为1像素).