大佬教程收集整理的这篇文章主要介绍了Android – 如何从资源中显示图像?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
ImageGetter imageGetter3 = new ImageGetter() { public Drawable getDrawable(String sourcE) { int id=0; if (source.equals("smiley")) { id = R.drawable.smiley; } Drawable d = getresources().getDrawable(id); d.setBounds(0,d.geTintrinsicWidth(),d.geTintrinsicHeight()); return d; } }; directions += "je bent bij lokaal " + vertrek.getNaam() + "\n" + "Sta met je rug voor de deur\n" + Html.fromHtml("<img src=\"smiley\">",imageGetter3,null) + " Draai naar links\n";
我在跑步时在屏幕上看到的是@L_772_4@带有“obj”文字的小方块.
那有什么不对?无法读取图像或其他内容?
如何显示图像?
老实说,我已经google了很多,并尝试过ImageGetter的其他方法,但是它们似乎都没有用,我也试过了,它们不起作用:
ImageGetter imageGetter2 = new ImageGetter() { public Drawable getDrawable(String sourcE) { Drawable d = null; d = Drawable.createFromPath(sourcE); d.setBounds(0,d.geTintrinsicHeight()); return d; } }; ImageGetter imageGetter = new ImageGetter() { public Drawable getDrawable(String sourcE) { Drawable drawFromPath; int path = Route.this.getresources().getIdentifier(source,"drawable","com.prj56.tracingapp"); drawFromPath = (DrawablE) Route.this.getresources().getDrawable(path); drawFromPath.setBounds(0,drawFromPath.geTintrinsicWidth(),drawFromPath.geTintrinsicHeight()); return drawFromPath; } };
================================================== =======
if(….){
ImageView iv1 = new ImageView(this);
iv1.setImageresource(R.drawable.smiley);
directions += "je bent bij lokaal " + vertrek.getNaam() + "\n" + "Sta met je rug voor de deur\n"; HERE COMES THE IMAGE! BUT HOW TO DO THIS? It's within directions textview... directions += " Draai naar links\n"; }
getresources().getDrawable()在api 22中已弃用,因此您现在应该使用COntextCompat.getDrawable,例如
Drawable d = ContextCompat.getDrawable(context,R.drawable.smiley);
在您的活动中,您可以调用此方法将Drawable资源作为Drawable对象
Drawable d = getresources().getDrawable(R.drawable.smiley);
如果要在ImageView中显示可绘制的内容,可以执行以下操作:
ImageView i = new ImageView(this); i.setImageresource(R.drawable.smiley);
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/smiley"/>
以上是大佬教程为你收集整理的Android – 如何从资源中显示图像?全部内容,希望文章能够帮你解决Android – 如何从资源中显示图像?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。