我在Android中有兩個主要視圖:帶有一些文本框的頁眉佈局以及視圖組,它是不等高度元素網格的自己實現。正如你可以在圖片中看到:滾動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>
感謝您的支持,
感謝您的評論。 「ScrollViews只能有一個子部件,如果你想要更多的孩子,可以將它們包裝在一個容器佈局中。」 –
將當前使用的佈局僅用作ScrollView的子項。這就是我所說的「圍繞你的整個佈局」。 – dst
嗨dst,這是不夠的,因爲我需要拉伸ViewGroup。我怎樣才能做到這一點,以便能夠滾動到ViewGroup的結尾? –