从URL加载图像 [英] Load images from URL

查看:133
本文介绍了从URL加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照下面的教程来加载一些图片在我的应用程序:

I am trying to load some images in my app according to the following tutorial:

http://www.anddev.org/novice-tutorials-f8/imageview-with-loading-spinner-t49439.html

我的问题是,我想有相同的XML文件,我所有的课程,只是改变负载图像的URL。

My problem is that I would like to have the same XML file for all my classes and just change the URL of the load image.

我用这个code在我的的.java 文件:

I'm using this code in my .java file:

final LoaderImageView image = new LoaderImageView(this, 
                                          "http://kostas-menu.gr/chania/santrivani.jpg");
image.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
                                       LayoutParams.WRAP_CONTENT));

这在我的xml:

And this in my xml:

<com.example.android.LoaderImageView
   android:layout_marginTop="10px"
   android:id="@+id/loaderImageView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:gravity="center"
   image="http://developer.android.com/images/dialog_buttons.png"
   />

我想删除行图像=htt​​p://developer.android.com/images/dialog_buttons.png,但如果我这样做,我没有得到任何图像。

I would like to erase the line image="http://developer.android.com/images/dialog_buttons.png"but if I do it I'm not getting any image.

我怎么能调用一个单独的图像从我的班?

How could I call a separate image from my class?

推荐答案

我会简单地使用的ImageView 您的布局(这可能有一个虚拟画面),然后使用Java来替换图片:链接

I would simply use an ImageView on your Layout (which maybe has a dummy-picture) and then use Java to replace the Image: Link

这篇关于从URL加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆