android水平滚动视图

android水平滚动视图,android,horizontal-scrolling,Android,Horizontal Scrolling,我是android开发的初学者,我正在尝试创建一个包含不同布局的水平滚动视图 我面临的错误是:水平滚动视图只能承载一个直接子对象。 请提前告知谢谢 <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tool" android:id="@+id/horizontalScrollV

我是android开发的初学者,我正在尝试创建一个包含不同布局的水平滚动视图

我面临的错误是:水平滚动视图只能承载一个直接子对象。 请提前告知谢谢

<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>

不仅水平滚动视图,任何垂直滚动视图都会出现此错误。 该错误意味着一个scrollview应该只有一个子项,并且该子项可以包含任意数量的子项

因此,底线是thios,您应该只将一个直接子对象设置为scrollview,并将该子对象中的布局设置为

  <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布局中创建所需的布局。您将不会得到任何错误,然后

您好。此错误是因为scrollview只能在direcxt子级上承载。
选择一个相对或线性布局,将所有布局都写在其中

你能更准确地定义你的问题吗?你怎么说不同的布局?我会考虑每个布局作为一个观点是没有什么错误的布局。一切都被适当地封装了。一切都在水平滚动视图中的一个线性布局中。不管你在一个线性布局中放了多少东西,它们都会向左/向右滚动。这可能是模拟器的问题吗?嗯,也许,模拟器并不完美。ScrollView布局仅在其内容超出屏幕边界时才有效。如果所有东西都放在一个屏幕上,他们什么也不做。如果您看到在原始问题中编写的错误,请尝试重新启动IDE。我没有看到那个错误,我照样复制了代码。它甚至可以在我的手机上运行,我已经设置了一些按钮。其他布局已经是此主布局的子级,而不是滚动视图的子级。这在我的eclipse上没有显示任何错误。如果您希望看到效果,请为不同的布局指定宽度,并为主布局指定fillparent宽度,您将看到滚动效果。