滚动单击android中的下一步和后退按钮

时间:2012-09-22 07:24:57

标签: android android-layout button scroll scrollview

我在Android中滚动时出现了一个小问题。这是我的xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<VideoView 
    android:layout_height="match_parent"
    android:layout_width="fill_parent"
    android:id="@+id/video"
    />

<RelativeLayout 
    android:layout_width="fill_parent"      
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:visibility="invisible"
    android:id="@+id/channelview" >

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/back"
        android:layout_alignParentLeft="true"
        android:id="@+id/backbtn"
        />

    <HorizontalScrollView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/backbtn"
        android:layout_toLeftOf="@+id/nextbtn"
        android:id="@+id/scroll" >

        <LinearLayout
            android:id="@+id/imageholder"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal" >
        </LinearLayout>
    </HorizontalScrollView>

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/next"
        android:layout_alignParentRight="true"
        android:id="@+id/nextbtn"
        />

</RelativeLayout>    

问题是我将动态添加Imageviews(超过50多个)添加到线性布局中,我不确定如何通过单击水平滚动视图两侧添加的下一个和上一个按钮来滚动它。默认情况下,如果我在滚动视图上滑动它会滚动,但我想通过单击按钮滚动任一方式。任何人都可以建议我如何使用示例代码完成它。感谢。

1 个答案:

答案 0 :(得分:1)

这样滚动视图可以向上或向下滚动。

scrollview.post(new Runnable() {

    @Override
    public void run() {
        // to scroll down
        scrollview.fullScroll(ScrollView.FOCUS_DOWN);
        // to scroll up
        scrollview.fullScroll(ScrollView.FOCUS_UP);
    }
});