1

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 以上) 追加していて、水平スクロールビューの両側に追加された次のボタンと前のボタンをクリックしてスクロールする方法がわからないことです。デフォルトでは、スクロールビューをスワイプするとスクロールしますが、ボタンをクリックしてどちらの方向にもスクロールしたいです。サンプルコードでそれを行う方法について誰かが私に提案できますか? ありがとう。

4

1 に答える 1

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);
    }
});
于 2012-09-22T07:32:15.733 に答える