Просмотр внутри ScrollView не занимает места
У меня есть RelativeLayout внутри ScrollView.
Мой RelativeLayout имеет android:layout_height="match_parent"
, но представление не принимает весь размер, он как wrap_content.
Есть ли способ иметь реальное поведение fill_parent/match_parent?
Мой макет:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="@drawable/top" />
<ImageView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/top"
android:scaleType="fitXY"
android:src="@drawable/headerbig" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/header"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:src="@drawable/logo" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom"
android:layout_below="@+id/logo"
android:background="@drawable/background" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/dashboard01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/dashboard02"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:src="@drawable/dashboard01"
android:visibility="visible" />
<ImageView
android:id="@+id/dashboard02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="@drawable/dashboard02" />
<ImageView
android:id="@+id/dashboard03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/dashboard02"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:src="@drawable/dashboard03"
android:visibility="visible" />
</RelativeLayout>
</ScrollView>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/logo"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="@drawable/bar" />
<ImageView
android:id="@+id/bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:scaleType="fitXY"
android:src="@drawable/bottom" />
</RelativeLayout>
Ответы
Ответ 1
Попробуйте добавить android:fillViewport="true"
в свой ScrollView
помните, что android:layout_height="fill_parent"
означает "установить высоту в высоту родителя". Это явно не то, что вы хотите, используя ScrollView
. В конце концов, ScrollView
станет бесполезным, если его содержание всегда будет таким же высоким, как и сам. Чтобы обойти это, вам нужно использовать атрибут ScrollView под названием android:fillViewport
. Если установлено значение true, этот атрибут заставляет дочерние элементы прокрутки расширяться до высоты ScrollView
, если это необходимо. Когда ребенок выше, чем ScrollView
, атрибут не действует.
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/