简体   繁体   English

如果图像处于drawable-xxhdpi,则部分显示

[英]Image displayed partially if in drawable-xxhdpi

I'm displaying an image through an ImageSwitcher with this factory: 我正在使用此工厂通过ImageSwitcher显示图像:

    view_background.setFactory {
        val imageView = ImageView(this@MainActivity)
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        imageView
    }

And I'm displaying correctly this 2341x1246 PNG 2.55 MB image on a Nexus 5 emulator: 而且我在Nexus 5模拟器上正确显示了2341x1246 PNG 2.55 MB图片:

在此处输入图片说明

However, if I use it on Nexus 6, it crashes: 但是,如果我在Nexus 6上使用它,则会崩溃:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.llovagn.t4r, PID: 4693
    java.lang.RuntimeException: Canvas: trying to draw too large(142936136bytes) bitmap.

By putting it in drawable-xxhdpi as suggested in this answer, it now look like this on both devices: 通过按照答案的建议将其放入drawable-xxhdpi ,现在在两个设备上都看起来像这样:

在此处输入图片说明

Which I something that I don't really want (the first way is the correct one). 我不想要的东西(第一种方法是正确的方法)。 Why and how can I solve this? 为什么以及如何解决这个问题?

2341x1246 PNG 2.55 MB 2341x1246 PNG 2.55 MB

Canvas: trying to draw too large ( 142936136bytes ) bitmap 画布: 试图绘制太大的位图( 142936136bytes

This doesn't look like a good approach. 这似乎不是一个好方法。 Reduce the size of the image and put the image in the drawable directory. 减小图像的尺寸,然后将图像放在drawable目录中。

It happens because you put the picture inside "drawable- xxhdpi ". 这是因为您将图片放在“ drawable- xxhdpi ”中。 Take a look at the sizes in here . 看一下这里的尺寸。

However, after doing what I suggested, use FIT_XY to fit the image: 但是,按照我的建议进行操作之后,请使用FIT_XY调整图像大小:

imageView.scaleType = ImageView.ScaleType.FIT_XY

You won't need 2.5 MB image in your application. 您的应用程序中不需要2.5 MB的图像。 That's pretty too much with that size. 这样的大小实在太多了。

To avoid this error try to use as small resolution of image as possible, also the image view should also be small, you could also get OOM on bigger and high res devices. 为避免此错误,请尝试使用尽可能小的图像分辨率,而且图像视图也应该很小,您也可以在较大和高分辨率的设备上获得OOM。 Best way would be to use a png image on a background view where background can be solid color or gradient. 最好的方法是在背景视图上使用png图像,其中背景可以是纯色或渐变。 By this way you can use smaller images that might not need to fill the whole screen size. 通过这种方式,您可以使用较小的图像,这些图像可能不需要占据整个屏幕尺寸。

暂无
暂无

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

相关问题 eclipse会识别drawable-xxhdpi文件夹吗? - would eclipse recognise drawable-xxhdpi folder? 如何将所有图像放入“ drawable-xxhdpi”阵列中? 特别是在“垫子”阵列中? - How to put all image in “drawable-xxhdpi” in an array? specifically in “Mat” array? ADT插件未在Eclipse中创建drawable-xxhdpi文件夹 - drawable-xxhdpi folder not created in Eclipse by ADT plugin drawable-xxhdpi的正确大小图标是什么? - What's the correct size icon for drawable-xxhdpi? (Android)如果仅将图像文件放在drawable-xxhdpi文件夹中,它是否可以在具有各种密度的所有设备中使用 - (Android) If I put an image file only in drawable-xxhdpi folder, is it working in all devices which have various densities Galaxy S4从drawable-sw360dp-hdpi而不是drawable-xxhdpi中选择资源? - Galaxy S4 picking resource from drawable-sw360dp-hdpi instead of drawable-xxhdpi? 我是否需要使用所有drawable,drawable-mdpi,drawable-hdpi,drawable-xhdpi,drawable-xxhdpi和drawable-xxxhdpi? - Do I need to use all of drawable, drawable-mdpi, drawable-hdpi, drawable-xhdpi, drawable-xxhdpi & drawable-xxxhdpi? DRAWABLE-V21 中的 Android drawble-xhdpi、drawable-xxhdpi、drawable-xxxhdpi 子文件夹也适用于 DRAWABLE-V23? - Android drawble-xhdpi, drawable-xxhdpi, drawable-xxxhdpi subfolders inside DRAWABLE-V21 also for DRAWABLE-V23? XXHDPI中的可绘制箭头 - Drawable Arrow in XXHDPI xxhdpi的图像比例是多少? - What is the image ratio of xxhdpi?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM