简体   繁体   English

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

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

I have a problem with my ScrollView. 我的ScrollView有问题。 It has an ImageView inside it. 它里面有一个ImageView。 The imageView holds an image which is 480 * 3000 px. imageView包含480 * 3000 px的图像。 So It needs to be in a ScrollView so the user will have the ability to scroll down. 因此,它必须在ScrollView中,以便用户能够向下滚动。

The problem is: when I test the application, the ScrollView does not wrap to the image hight. 问题是:当我测试应用程序时,ScrollView不会包装到图像较高的位置。 There is a black space under the image which is strange for me. 图像下方有一个黑色空间,这对我来说很奇怪。

This is my XML code. 这是我的XML代码。 I look forward for your opinion 期待您的意见

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

Update: This is how my image looks like with @ruhalde code. 更新:这是使用@ruhalde代码显示的图像。 I can't take a screenshoot since it is big and you'll not see the whole picture so I draw it. 我无法进行屏幕截图,因为它很大,您看不到整个图片,所以我将其绘制出来。

在此处输入图片说明

Rewrite your layout. 重写您的布局。 Make the ScrollView the outer most element. 使ScrollView成为最外面的元素。 Take a look at this good tutorial for more information: http://mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts 看看这个很好的教程以获取更多信息: http : //mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts

Use a LinearLayout instead of RelativeLayout which is deprecated by now. 使用LinearLayout代替目前不推荐使用的RelativeLayout。 Set fillViewPort=true in your ScrollView XML or programatically if you want with setFillViewPort(true). 在ScrollView XML中设置fillViewPort = true,或者如果需要,通过编程设置setFillViewPort(true)。

Put imageview inside a LinearLayout and that inside ScrollView, your XML should look like this: 将imageview放在LinearLayout和ScrollView内,您的XML应该如下所示:

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

Check out my XML here working good with a 800 x 4000 pixels image, perfectly scrolling vertical: 在这里查看我的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>

To those who might be interested: 对于那些可能感兴趣的人:

My problem was with the image I'm using, not how I organize my layouts. 我的问题是我使用的图像,而不是布局方式。 Thanks. 谢谢。

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

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

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