简体   繁体   English

ScrollView中的Android ImageView显示白屏

[英]Android ImageView in ScrollView shows white screen

I want to show an image which is longer than the screen. 我想显示的image比屏幕

I'm using an ImageView inside a scroll view . 我在scroll view使用ImageView I get a white screen , which is scrollable to the height of the image , but the image itself is not presented . 我得到一个白色的屏幕 ,该屏幕 可滚动imageheight ,但是图像本身未显示

Here's the layout xml I'm using :- 这是我正在使用的布局xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    tools:context=".MainActivity" >


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/test_image_content_description"
        android:adjustViewBounds="true"
        android:visibility="visible"
        android:src="@drawable/test_image" />

</ScrollView>

test_image.png is a file which is available in all the " drawable " folders of the application . test_image.png是一个文件,可以在应用程序的所有“ drawable ”文件夹中找到。

Any help would be greatly appreciated! 任何帮助将不胜感激!

In your ScrollView , 在您的ScrollView

Change android:layout_height="wrap_content" to android:layout_height="math_parent" android:layout_height="wrap_content"更改为android:layout_height="math_parent"

you can add a scaletype to your imageview, like use android:scaleType="center" to center image with no scale, and then you should remove the code android:adjustViewBounds="true" from imageview. 您可以向您的imageview添加一个scaletype,例如使用android:scaleType="center"将没有缩放比例的图像居中,然后您应从imageview中删除代码android:adjustViewBounds="true" Please see ImageView.ScaleType for details. 有关详细信息,请参见ImageView.ScaleType Thanks 谢谢

Ok, I found the problem. 好的,我发现了问题。 It seems that the problem was that the image had height of 6000 pixels, and the max size Android is willing to display (even inside ScrollView) is of 4096 (even if I add scaling). 似乎问题在于图像的高度为6000像素,Android愿意显示的最大尺寸(即使在ScrollView内部)也为4096(即使我添加了缩放比例)。

After resizing the image, it is shown without a problem. 调整图像大小后,显示没有问题。

Thank you all for the replies! 谢谢大家的答复!

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

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