0

私はファミリーツリーアプリに取り組んでいます。これで、ツリー ビューを大きくすることができ、ユーザーが左右に移動できるようになりました (たとえば、兄弟が 7 人いる場合)。しかし、ツリー ビューを開くと、常に左隅から始まり、右にスクロールして詳細を表示できます。ツリービューを常にレイアウトの途中で開くようにしたい。

コードは次のとおりです。

    <?xml version="1.0" encoding="UTF-8"?>
    <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/HorizontalScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/light_green" >

    <LinearLayout
        android:id="@+id/Top_Level_View_Family_Tree"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/TextView_view_family_members_title"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="3"
            android:text="Family Tree"
            android:gravity="center_horizontal"
            android:textSize="@dimen/font_large" />

        <LinearLayout
            android:id="@+id/Family_Tree_parentLL"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="4"
            android:gravity="center_horizontal"
            android:orientation="horizontal"  >
        </LinearLayout>

        <LinearLayout
            android:id="@+id/Family_Tree_yourLL"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="4"
            android:gravity="center_horizontal"
            android:orientation="horizontal" >
        </LinearLayout>
        <LinearLayout
            android:id="@+id/Family_Tree_siblingLL"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="4"
            android:gravity="center_horizontal"
            android:orientation="horizontal" >
        </LinearLayout>

        <LinearLayout
            android:id="@+id/Family_Tree_childLL"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="4"
            android:gravity="center_horizontal"
            android:orientation="horizontal" >
        </LinearLayout>
    </LinearLayout>

</HorizontalScrollView>

ここにアプリがあります:
http://img838.imageshack.us/img838/310/appa.png

すばらしいヘルプ: Android は、Horizo​​ntalScrollView で scrollTo の位置を計算します

4

1 に答える 1

0

コードで配置する必要がありますが、XML ではできません。scrollToこれを行うには、 の方法を使用しHorizontalScrollViewます。トップレベルの LinearLayout の幅に基づいて、スクロールする必要がある位置を計算する必要があります。

次のようなもの:

HorizontalScrollView hView = findViewById( R.id.HorizontalScrollView01 );
LinearLayout lin = findViewById( R.id.Top_Level_View_Family_Tree );

int width = lin.getWidth();
hView.scrollTo( width / 2, 0 );

ここで、scrollToスクロールするのに適切な位置ではないと確信しているため、その部分を編集する必要があります。おそらく、ビューの左側の位置にスクロールします。私が行ったことは、それが中心。計算をいじって、あなたが望むようにする必要があります。

于 2012-11-29T18:19:29.993 に答える