如何在Android中显示来自此HREF的图像。
http://www.sandesh.com/article.aspx?newsid=3048433'>http://www.sandesh.com/uploadimages/national/News2_20150302194317737.jpg'/>
答案 0 :(得分:1)
我认为这可能是你想要的。查看此问题,了解原始代码:How to load an ImageView by URL in Android?
// show The Image
new DownloadImageTask((ImageView) findViewById(R.id.imageView1))
.execute("http://java.sogeti.nl/JavaBlog/wp-
content/uploads/2009/04/android_icon_256.png");
}
public void onClick(View v) {
startActivity(new Intent(this, IndexActivity.class));
finish();
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
并在Android Manifest文件中设置正确的用户权限。
<uses-permission android:name="android.permission.INTERNET" />
答案 1 :(得分:0)
您可以使用毕加索图书馆
Picasso.with(context)
.load("http://www.sandesh.com/uploadimages/national/News2_20150302194317737.jpg")
.placeholder(R.drawable.your_place_holder_drawable) //optional
.error(R.drawable.your_errorRes_drawable)//optional
.into(yourImageViewInstane);
在build.gradle文件中
dependencies {
...
compile 'com.squareup.picasso:picasso:2.4.0'
}