Android ScrollView 内的视图不会全部发生
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10211338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
View inside ScrollView doesn't take all place
提问by g123k
I have a RelativeLayout inside a ScrollView.
My RelativeLayout has android:layout_height="match_parent"
but the view doesn't take the entire size, it's like a wrap_content.
我在 ScrollView 中有一个 RelativeLayout。我的RelativeLayout 有,android:layout_height="match_parent"
但视图没有占据整个尺寸,它就像一个wrap_content。
Is there a way to have the real fill_parent/match_parent behavior ?
有没有办法拥有真正的 fill_parent/match_parent 行为?
My layout :
我的布局:
<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>
回答by Sam Dozor
Try adding android:fillViewport="true"
to your ScrollView
尝试添加android:fillViewport="true"
到您的 ScrollView
remember that
android:layout_height=”fill_parent”
means “set the height to the height of the parent.” This is obviously not what you want when using aScrollView
. After all, theScrollView
would become useless if its content was always as tall as itself. To work around this, you need to use the ScrollView attribute calledandroid:fillViewport
. When set to true, this attribute causes the scroll view's child to expand to the height of theScrollView
if needed. When the child is taller than theScrollView
, the attribute has no effect.
请记住,这
android:layout_height=”fill_parent”
意味着“将高度设置为父级的高度”。这显然不是您在使用ScrollView
. 毕竟,ScrollView
如果它的内容总是和它自己一样高,它就会变得毫无用处。要解决此问题,您需要使用名为 的 ScrollView 属性android:fillViewport
。当设置为 true 时,ScrollView
如果需要,此属性会导致滚动视图的子级扩展到 的高度。当孩子高于 时ScrollView
,该属性无效。
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
回答by virendra singh deora
Just add android:fillViewport="true" in yout xml layout in Scrollview
只需在 Scrollview 的 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>