在ScrollView中查看并不是全部 [英] View inside ScrollView doesn't take all place

查看:68
本文介绍了在ScrollView中查看并不是全部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ScrollView中有一个RelativeLayout. 我的RelativeLayout的尺寸为android:layout_height="match_parent",但视图的大小并不完整,就像wrap_content一样.

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.

有没有办法实现真正​​的fill_parent/match_parent行为?

Is there a way to have the real fill_parent/match_parent behavior ?

我的布局:

<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>

推荐答案

尝试将android:fillViewport="true"添加到ScrollView

Try adding android:fillViewport="true"to your ScrollView

请记住,android:layout_height=fill_parent的意思是将高度设置为父级的高度."当使用ScrollView时,这显然不是您想要的.毕竟,如果ScrollView的内容总是和它本身一样高,它将变得毫无用处.若要解决此问题,您需要使用名为android:fillViewport的ScrollView属性.设置为true时,如果需要,此属性会使滚动视图的子级扩展到ScrollView的高度.当孩子长于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 a ScrollView. After all, the ScrollView would become useless if its content was always as tall as itself. To work around this, you need to use the ScrollView attribute called android:fillViewport. When set to true, this attribute causes the scroll view’s child to expand to the height of the ScrollView if needed. When the child is taller than the ScrollView, the attribute has no effect.

http://www.curious-creature.org /2010/08/15/scrollviews-handy-trick/

这篇关于在ScrollView中查看并不是全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆