私はファミリーツリーアプリに取り組んでいます。これで、ツリー ビューを大きくすることができ、ユーザーが左右に移動できるようになりました (たとえば、兄弟が 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 は、HorizontalScrollView で scrollTo の位置を計算します