0

我的 ScrollView 有问题。它里面有一个 ImageView。imageView 包含一个 480 * 3000 像素的图像。所以它需要在 ScrollView 中,这样用户才能向下滚动。

问题是:当我测试应用程序时,ScrollView 没有包装到图像高度。图像下方有一个黑色空间,这对我来说很奇怪。

这是我的 XML 代码。我期待你的意见

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical" >    
        <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/image"
        android:src="@drawable/image01"
        android:scaleType="fitStart" />     
    </ScrollView>
</RelativeLayout>

更新: 这就是我的图像使用@ruhalde 代码的样子。我不能截图,因为它很大,你不会看到整个画面,所以我画了它。

在此处输入图像描述

4

4 回答 4

0

重写你的布局。使 ScrollView 成为最外层的元素。看看这个很好的教程了解更多信息: http: //mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts

于 2011-08-22T01:13:04.127 回答
0

使用 LinearLayout 而不是现在已弃用的 RelativeLayout。在您的 ScrollView XML 中设置 fillViewPort=true,或者如果您想使用 setFillViewPort(true) 以编程方式设置。

将 imageview 放在 LinearLayout 和 ScrollView 中,您的 XML 应该如下所示:

LinearLayout ---ScrollView ----LinearLayout ------ImageView

在这里查看我的 XML,使用 800 x 4000 像素的图像效果很好,可以完美地垂直滚动:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ScrollView android:id="@+id/scrollView1"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <LinearLayout android:id="@+id/linearLayout1"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <ImageView android:id="@+id/mapa" android:layout_height="wrap_content"
                android:layout_width="wrap_content"></ImageView>
        </LinearLayout>
    </ScrollView>

</LinearLayout>
于 2011-08-22T02:17:01.687 回答
0

对于那些可能感兴趣的人:

我的问题在于我正在使用的图像,而不是我如何组织布局。谢谢。

于 2012-01-12T00:51:20.777 回答
-1

我相信你应该在你的布局标签之前使用 scrollView 标签

于 2011-08-22T01:28:36.073 回答