9

私はアンドロイド開発の初心者で、さまざまなレイアウトを含む水平スクロール ビューを作成しようとしています。

私が直面しているエラーは次のとおりです。水平スクロールビューは、直接の子を1つしかホストできません。アドバイスください 事前に感謝します

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tool"
        android:id="@+id/horizontalScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true" >

         <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:background="#ff0000">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:orientation="horizontal"
                android:background="#ff0000">

            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:orientation="horizontal"
                android:background="#00ff00">

            </LinearLayout>

        </LinearLayout>

    </HorizontalScrollView>
4

2 に答える 2

11

水平スクロールビューだけでなく、垂直スクロールビューでもこのエラーが発生します。このエラーは、スクロールビューの子は 1 つだけであるべきであり、その子には任意の数のサブ子を含めることができることを意味します。

要するに、スクロールビューに直接の子を1つだけ作成し、その子でレイアウトを次のようにのみ作成する必要があるチオスです。

  <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tool"
    android:id="@+id/horizontalScrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" >

     <LinearLayout

        android:id="@+id/directchild"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:background="#ff0000">

    </LinearLayout>

</HorizontalScrollView>

次に、directchild レイアウト内に目的のレイアウトを作成します。その後、エラーは発生しません。

于 2012-10-15T17:27:13.327 に答える