g12*_*23k 131 layout android scrollview
我在ScrollView中有一个RelativeLayout.我的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>
Run Code Online (Sandbox Code Playgroud)
Sam*_*zor 423
尝试添加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/
小智 6
只需在Scrollview中的youx xml布局中添加android:fillViewport ="true"即可
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/green"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fitsSystemWindows="true"
android:fillViewport="true"
>
<!--define views here-->
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
42588 次 |
最近记录: |