java - 我如何解决在 xml 文件上添加图像以进行 Android 开发的问题?

标签 java android android-studio

在我的 xml 代码中,对于 Android 开发,我在屏幕上添加图像时遇到问题。

enter image description here

我的图像I1工作正常... 但是当我在代码中使用图像 I2 时会出现问题。我不知道为什么,但当我使用 I2 图像打开它时,我的应用程序崩溃了。但我使用了 I1 而不是 I2。然后就可以正常使用了。

为什么会发生......? 有什么解决办法吗......??

最佳答案

应用程序崩溃,因为将图像加载到 ImageView 中太大,应用程序无法处理,因此出现 OutOfMemoryException

您需要做的是使用一些已经针对管理图像进行了优化的库

尝试使用

https://square.github.io/picasso/

https://github.com/bumptech/glide

将图像加载到 ImageView

关于java - 我如何解决在 xml 文件上添加图像以进行 Android 开发的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62239209/

相关文章:

java - JPA 中谓词的表达式解析器

java - 无法将日期从字符串写入 TextView

java - 如何在 sql-server 数据库表上构建自由流搜索?

java - 如何确保在 Apache Tomcat 中运行的 Spring Boot 应用程序中替换了环境变量占位符?

java - 多次执行 Runnable post 到 Looper 的 Activity

java - 按后退按钮显示相同的 Activity

android - IONIC添加android平台

android - 如何在我的内容提供商中获取 _count?

android - 现有 gradle 项目中的 Git 子模块

android - a failure occurred while executing com.android.build.gradle.internal.tasks.workers$actionfacade