Android:Scrollview延伸背景图片

cap*_*com 5 android android-layout

所以我试图让我的活动可滚动,当我将relativelayout放在滚动视图中时,会发生这种情况:

在此输入图像描述

这是上面截图的代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background"
        android:orientation="vertical"
        android:paddingLeft="60dp"
        android:paddingTop="53dp" >

        <ImageView
            android:id="@+id/gearImage"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginTop="70dp"
            android:clickable="true"
            android:contentDescription="@string/gearDescription_string"
            android:src="@drawable/gear" />
    </RelativeLayout>

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

如果我取出滚动视图,结果是正确的,但当然没有我想要的滚动功能:

在此输入图像描述

现在,有什么方法可以让它看起来像这样:

在此输入图像描述

所以我仍然可以滚动,但如果它们到达我所拥有的背景图像的底部,它只是白色(很难分辨,因为网页的背景是白色的,但我在第二个图像的底部添加了一个白色矩形显示我的意思).无论如何,他们没有理由到达底部.

当然,如果你对如何实现滚动视图有任何其他建议而不通过背景图像拉伸,我会非常高兴听到它们.

谢谢.

ove*_*t13 6

退房android:fillViewport.根据文档,这个defines whether the scrollview should stretch its content to fill the viewport.将以下代码添加到您的ScrollView:

android:fillViewport="true"
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.

编辑:

请尝试以下方法:

  1. ScrollView设置上android:layout_height="fill_parent"
  2. RelativeLayout设置上android:layout_height="wrap_content"


cap*_*com 1

它不起作用的原因是我的图像像素太大。我猜滚动视图被迫将图像保持其原始大小,所以它所做的就是这样。它使长度成为原始图像的全长,因为我的滚动视图是垂直的,并且沿着宽度挤压它,因为我没有从一边到另一边的滚动视图。

简单的修复方法就是缩小图像。它可以在正常布局内正确调整大小,但不能在滚动视图内正确调整大小,这真是太奇怪了。