垂直ScrollView中的水平ScrollView

时间:2015-09-23 18:29:01

标签: android scrollview vertical-scrolling

我正在开发一个带有ImageView的Horizo​​ntalScrollView的片段。我想将一个垂直ScrollView实现为父级,将Horizo​​ntalScrollView实现为其子级。我该如何实现呢?这是我的.xml文件与Horizo​​ntalScrollView: -

<!-- TODO: Update blank fragment layout -->
<SearchView
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:id="@+id/searchView"
    android:focusable="true"
    android:textStyle = "bold|italic"
    android:queryHint="@string/search"
    android:clickable="true"
    android:background="#ffffff" />

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:scrollbars="horizontal"
    android:id="@+id/horizontalScrollView">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/LoginFormContainer"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_marginRight="2dp"
            android:src="@drawable/picture1" />

        <ImageView
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:src="@drawable/picture2" />

        <ImageView
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:src="@drawable/picture3" />

        <ImageView
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:src="@drawable/picture6" />

        <ImageView
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:src="@drawable/hospital" />

        <ImageView
            android:layout_width="300dp"
            android:layout_height="200dp"
            android:layout_marginLeft="2dp"
            android:src="@drawable/picture7" />

    </LinearLayout>
</HorizontalScrollView>

1 个答案:

答案 0 :(得分:0)

ScrollView类用于垂直滚动,所以:

<SearchView
.../>
    <ScrollView
    .../>
        <HorizontalScrollView
        .../>
            <LinearLayout
            .../>
                <!-- Multiple views here -->
            </LinearLayout>
        </HorizontalScrollView>
    </ScrollView>
</SearchView>