注:原文转载自https://blog.csdn.net/xi_aoxin/article/details/58609588

感谢博主 xi_aoxin



首先,将所要显示的图片添加到res资源目录文件drawable-hdpi下,具体过程如下:

选择Project视图,app—>src—>res—>右键new resource directory—>选择resource type (drawable)->density,根据你的需要,选择合适的分辨率,这里选择high density确认后

会生成一个资源文件夹drawable-hdpi—>将图片文件复制到文件夹里,复制过程直接点击OK

即可,最后如图:

Android studio中使用ImageView时android:src属性出错问题解决方案!

其次,修改activity_main.xml中的代码
[html] view plain copy
  1. <ImageView  
  2.         android:id="@+id/image_view"  
  3.         android:layout_width="wrap_content"  
  4.         android:layout_height="wrap_content"  
  5.         android:src="@drawable/img"  
  6.         />  

然后,点击run,选择模拟器,运行时出现以下错误,如图

Android studio中使用ImageView时android:src属性出错问题解决方案!

---------------------分隔符-------------------------

分析:出现这种错误的原因是资源文件(图片格式)的解析错误,因为这里

用到的图片是用户直接修改过后缀名的,解决方法就是用ps软件修改文件的

格式为.png。注意:这里只能使用ps打开原图,否则ps会报源文件格式损坏!



最后,将修改好的图片按照以上步骤添加进drawable-hdpi文件夹下,重新

点击run,运行成功!!!

Android studio中使用ImageView时android:src属性出错问题解决方案!


***转载请注明,谢谢!***

相关文章:

  • 2021-06-14
  • 2021-08-14
  • 2021-12-17
  • 2021-07-05
  • 2021-05-20
  • 2021-08-18
  • 2021-05-19
猜你喜欢
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2021-05-29
  • 2022-01-08
  • 2022-12-23
相关资源
相似解决方案