繁体   English   中英

Android ScrollView不会包装到其子级吗?

[英]Android ScrollView Doesn't wrap to its child?

我的ScrollView有问题。 它里面有一个ImageView。 imageView包含480 * 3000 px的图像。 因此,它必须在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代码显示的图像。 我无法进行屏幕截图,因为它很大,您看不到整个图片,所以我将其绘制出来。

在此处输入图片说明

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

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

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

我的问题是我使用的图像,而不是布局方式。 谢谢。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM