如何设置android Horizo​​ntalScrollView从右到左的行为(默认从右侧选择选项卡,而不是左侧)

pro*_*mer 5 android android-tabs

如何设置 Horizo​​ntalScrollView 以从右到左的方式运行?默认行为是显示的第一个选项卡(默认选项卡)位于左侧。我希望选项卡反向排序,以便第一个“默认”选项卡位于屏幕的右侧。

我怎么做?我使用了layout_gravity,但它不起作用..

这是我的布局代码,包含 tabhost 和 Horizo​​ntalScrollView:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:scrollbars="none">

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </HorizontalScrollView>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>

</TabHost>
Run Code Online (Sandbox Code Playgroud)

mid*_*ido 4

一种有效的解决方法:

final HorizontalScrollView view = (HorizontalScrollView) findViewById(R.id.scroller);
        view.postDelayed(new Runnable() {

            @Override
            public void run() {
                view.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
            }
        }, 10);
Run Code Online (Sandbox Code Playgroud)

这个想法是,程序化滚动需要延迟才能发挥作用。