“Canvas: trying to draw too large bitmap” when Android N Display Size set larger than Small

编译时报了这个错,以前从没有出现过。网上搜索了半天都是一些错误的答案,实在是很想吐槽某度。。。
上Stack Overflow一搜就解决了,这里记录一下,怕忘记。
Stack Overflow上的原答案:
I my case, moving the (hi-res) splash bitmap from drawable to drawable-xxhdpi was the solution.

I had the same problem. I didn’t suspect my splash screen to be the problem, since it is displayed when the app is started, but it turned out the splash screen is the problem.

The splash screen in my case has xxhdpi resolution, and it was mistakenly placed in the drawable folder, instead of drawable-xxhdpi. This made Android assume the splash screen had mdpi resolution and scale the image to 3*3 times it’s required size and trying to create a bitmap.
这里就不翻译了,意思就是说你将高分辨率图片放在了低分辨率文件夹下。
例如:图片的分辨率是属于xxhdpi的,而你将这张图片放在了drawable-xhdpi或者比这个还低的文件夹下,就会报这个错,解决的办法:
1.人为的将这张图片的分辨率降低(一般不这样做)
2.将高分辨率的图片放在drawable-xxhdpi或者drawable-xxxhdpi下即可

当然,之所以会出现这些问题都是UI切图不注意大小或者工程师放置图片位置不规范导致的,如果严格的按照andorid开发规范的要求来做的话,是根本不会出现这种问题的。

更新:
采用第二种方式的话,在调试安装apk的时候是没有问题的,但是在打包安装的时候会报软件包安装程序已停止的错误,原因是drawable-xhdpi文件夹下没有图片,将图片分辨率降低放入drawable-xhdpi文件夹下再次打包安装就没有问题了。

猜你喜欢

转载自blog.csdn.net/liuxiaopang520/article/details/78223841
今日推荐