0

我在 Android 中有一个具有两个主要视图的活动:一个带有一些文本框的标题布局,以及一个视图组,它是不等高元素网格的自己实现。如图所示:

在此处输入图像描述

我希望不仅能够滚动视图中的元素,而且能够滚动整个活动。我无法将 setHeaderView 用于列表,因为它不是 ListView,它是 ViewGroup 的子类。我无法做到这一点:-(

这是我尝试使用的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#E0E0DE"
    tools:context=".MainActivity" >

    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/layout_action_bar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin" >

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="200dp" >

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/background"
                    android:scaleType="centerCrop"
                    android:adjustViewBounds="true" />

                <include
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    layout="@layout/layout_search_view"
                    android:layout_centerInParent="true"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp" />

            </RelativeLayout>

            <include
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                layout="@layout/layout_location_info" />

            <com.tenea.turipolis.UnequalGridView
                android:id="@+id/listPictures"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical"
                android:columnCount="2"
                android:padding="2dp"
                android:verticalSpacing="2dp"
                android:horizontalSpacing="2dp" />

        </LinearLayout>

    </ScrollView>

</LinearLayout>

谢谢你的支持,

4

2 回答 2

2

ScrollView包围你的整个布局。

于 2013-08-05T13:37:28.573 回答
0

将您的布​​局包装在:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

// your layout here

</ScollView>

您只能有一个子小部件,例如:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

    // your layout here

    </LinearLayout>

</ScollView>
于 2013-08-05T13:54:23.217 回答