开发者

How to set a PNG file to an ImageView?

开发者 https://www.devze.com 2023-01-18 04:17 出处:网络
I have a file called nochart.png in /drawable. How can I set this to an ImageView? chartImageView.se开发者_如何学GotImageDrawable(R.drawable.nochart);

I have a file called nochart.png in /drawable.

How can I set this to an ImageView?

chartImageView.se开发者_如何学GotImageDrawable(R.drawable.nochart);

Does not compile.


Use:

chartImageView.setImageResource(R.drawable.nochart);


you can also set the image using an xml file with the following attriblute

android:src="@drawable/nochart"


I encountered the same problem. The solution for me was to move the ".png" from "drawable-21" to "drawable".


just put your .png file in mipmap folder

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号