Android: 自动滚动的 HorizontalScrollView

5
我正在使用以下代码模拟选项卡,由于选项卡的数量超出了宽度的容纳范围,用户可以向左或向右滚动以使选项卡按钮可见。这是有效的,然而我还提供了一个功能,即通过在选项卡内容上向左或向右滑动手指来切换选项卡。同样 - 这也是有效的。但是当我向最右边的选项卡滑动时,其对应的按钮几乎不可见。我想要在HorizontalScrollView中自动滚动表格,以便所选的选项卡按钮将可见,但是当我执行HorizontalScrollView.smoothScrollTo(300, 0)时,什么都没有发生。无论我设置第一个参数的值多高,任何东西都不会移动(是的,我确实有一个算法来计算精确位置)。
以下是滚动选项卡按钮的XML代码。
<HorizontalScrollView android:layout_width="fill_parent"
    android:background="@color/tabs_header" android:layout_height="55dip"
    android:scrollbars="none" android:id="@+id/tabsButtonView">
    <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent" android:layout_weight="1"
            android:layout_height="0dip" android:paddingTop="5dip" android:paddingLeft="3dip">
            <ImageButton android:src="@drawable/linkup_logo_small" android:id="@+id/tabBtt0"
                android:layout_width="wrap_content" android:layout_marginLeft="2dip" android:layout_marginRight="2dip"
                android:layout_height="fill_parent" android:padding="5dip" android:background="@drawable/tab_selected"></ImageButton>
            <ImageButton android:src="@drawable/simplyhired_small" android:id="@+id/tabBtt1"
                android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip" android:padding="5dip" android:background="@drawable/tab_normal"></ImageButton>
            <ImageButton android:src="@drawable/indeedcom_small" android:id="@+id/tabBtt2"
                android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dip"
                android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:background="@drawable/tab_normal"></ImageButton>
            <ImageButton android:src="@drawable/careerbuilder_logo_small" android:id="@+id/tabBtt3"
                android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dip"
                android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:background="@drawable/tab_normal"></ImageButton>
        </TableRow>
    </TableLayout>
</HorizontalScrollView>
1个回答

2

HorizontalScrollView 没有问题,自动滚动也完美运行。只是我的代码中初始化的顺序出了问题。案件结案。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接