0

私は例外を取得します:

java.lang.IllegalStateException: ScrollView can host only one direct child

これは私のレイアウトです:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg_listgrey"
    android:scrollbars="none" >

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/bg_listgrey" >

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/rl1">

            <ImageView
               />

            <TextView
                />

            <TextView
               />

            <TextView
                />
        </RelativeLayout>

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/rl2"" >

            <ImageView
                 />

            <TextView
                 />
        </RelativeLayout>
    </RelativeLayout>

</ScrollView>

アクティビティの場合、同じレイアウトがうまく機能しました。Fragmentで使用すると例外が発生します。

主な活動:

FragmentTransaction t = this.getSupportFragmentManager()
        .beginTransaction();
t.add(R.id.frame, new mFragment());
t.commit();

ありがとうございました

編集:

この ScrollView を FragmeLayout でラップすると、問題なく動作します。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg_listgrey" >

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="none" >
.......
.......
.......
</ScrollView>
</FramLayout>
4

1 に答える 1

1

アクティビティの場合、同じレイアウトがうまく機能しました。フラグメントで使用すると例外が発生します。

レイアウトは のコンテンツ ビューとして問題なく機能しますActivity(ただし、別のビューを に追加してみて、ScrollViewどうなるかを確認してください;)) Fragment。これ:

t.add(R.id.frame, new mFragment());

Fragment'sビュー ( で作成されたものonCreate) をScrollView(ScrollViewは idを持っています) に追加します。これは、に と のビューのルートのR.id.frame2 つのビューがあることを意味しますScrollView(これは許可されていません) 。クラスのメソッドは、 .RelativeLayoutFragmentaddViewScrollViewScrollView

この ScrollView を FragmeLayout でラップすると、問題なく動作します。

のビューを ではなくFragment親に追加するため、これは正常です。FrameLayoutScrollView

于 2012-12-09T15:21:30.250 に答える