5

次のコードを使用してタブをシミュレートしています。幅に対応できるタブがさらにあるため、ユーザーは左または右にスクロールしてタブボタンを表示できます。それはすべて機能しますが、タブの内容を指で左右にスワイプして、タブ間を移動する機能もユーザーに提供します。繰り返しますが、動作します。しかし、一番右のタブに移動すると、対応するボタンがほとんど見えません。HorizontalScrollView選択したタブボタンが表示されるようにテーブル内を自動スクロールしたいのですが、実行してHorizontalScrollView.smoothScrollTo(300, 0)も何も起こりません。最初のxパラメーターをどれだけ高く設定しても、何も移動しません(はい、正確な位置を計算するアルゴリズムがあります)。

タブ ボタンをスクロールするための 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>
4

1 に答える 1

2

Horizo​​ntalScrollView に問題はなく、自動スクロールは完全に機能しています。私のコードで失敗していたのは、単なる一連の初期化でした。ケースを閉じました。

于 2010-05-20T04:37:25.160 に答える