【问题标题】:smooth scroll to last tab in android horizontalscrollview在android Horizo​​ntalscrollview中平滑滚动到最后一个标签
【发布时间】:2013-04-23 07:56:29
【问题描述】:

我在布局的底部有八个带有水平滚动视图的选项卡。

现在我想要的是在该活动开始时,我想顺利滚动整个选项卡到最后一个选项卡。那么如何才能在水平滚动视图中平滑地滚动第一个选项卡到最后一个选项卡。

这是我的布局文件:

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:fadingEdge="none"
    android:overScrollMode="never"
    android:scrollbars="none" >

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:divider="@drawable/divider_tab" />

</HorizontalScrollView>

我尝试了一些代码,例如:

final HorizontalScrollView sv = (HorizontalScrollView)findViewById(R.id.horizontalScrollView);
sv.post(new Runnable() {
    public void run() {
        sv.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
    }
});

请帮我制作这个动画或滚动。

【问题讨论】:

    标签: android android-layout horizontal-scrolling android-scrollview


    【解决方案1】:

    我还在屏幕底部的活动中创建了 9 个选项卡。我可以非常流畅地滚动浏览所有选项卡。在 XML 中尝试以下代码:

    <?xml version="1.0" encoding="utf-8"?>
    

    <!-- xmlns:android="http://schemas.android.com/apk/res/android" -->
    
    <TabHost
        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" >
    
            <!-- <View -->
            <!-- android:layout_width="fill_parent" -->
            <!-- android:layout_height="0.5dip" -->
            <!-- android:background="#000" /> -->
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
    
            <View
                android:layout_width="fill_parent"
                android:layout_height="2dip"
                android:background="#696969" />
    
            <HorizontalScrollView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
    
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="0dip"
                    android:layout_marginRight="0dip" />
            </HorizontalScrollView>
    
            <!-- <View -->
            <!-- android:layout_width="fill_parent" -->
            <!-- android:layout_height="2dip" -->
            <!-- android:background="#000" /> -->
    
        </LinearLayout>
    </TabHost>
    

    希望对你有帮助..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多