Android在ImageView上直接显示网络图片
亲测可用,若有疑问请私信
在原生的ImageView中,没有一个方法是可以直接显示网络的图片的,当我们经常需要显示网络图片时,每次都有一大堆的操作,这会很麻烦,今天就教大家在ImageView上轻松显示网络图片。
自定义ImageView方法
写一个类让它继承ImageView,并增加一个setImageURL(path)方法
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class MyImageView extends ImageView {
public static final int GET_DATA_SUCCESS = 1;
public static final int NETWORK_ERROR = 2;
public static final int SERVER_ERROR = 3;
//子线程不能操作UI,通过Handler设置图片
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case GET_DATA_SUCCESS:
Bitmap bitmap = (Bitmap) msg.obj;
setImageBitmap(bitmap);
break;
case NETWORK_ERROR:
Toast.makeText(getContext(),"网络连接失败",Toast.LENGTH_SHORT).show();
break;
case SERVER_ERROR:
Toast.makeText(getContext(),"服务器发生错误",Toast.LENGTH_SHORT).show();
break;
}
}
};
public MyImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MyImageView(Context context) {
super(context);
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
//设置网络图片
public void setImageURL(final String path) {
//开启一个线程用于联网
new Thread() {
@Override
public void run() {
try {
//把传过来的路径转成URL
URL url = new URL(path);
//获取连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//使用GET方法访问网络
connection.setRequestMethod("GET");
//超时时间为10秒
connection.setConnectTimeout(10000);
//获取返回码
int code = connection.getResponseCode();
if (code == 200) {
InputStream inputStream = connection.getInputStream();
//使用工厂把网络的输入流生产Bitmap
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
//利用Message把图片发给Handler
Message msg = Message.obtain();
msg.obj = bitmap;
msg.what = GET_DATA_SUCCESS;
handler.sendMessage(msg);
inputStream.close();
}else {
//服务启发生错误
handler.sendEmptyMessage(SERVER_ERROR);
}
} catch (IOException e) {
e.printStackTrace();
//网络连接错误
handler.sendEmptyMessage(NETWORK_ERROR);
}
}
}.start();
}
}
在布局上不能使用ImageView,要使用MyImageView,要把刚才重写的一个MyImageView的全路径写上
<Button
android:text="加载网络图片"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button" />
<com.example.dell.myapplication.MyImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
在MainActivity上,只要调用setImageURL(),直接把网络的图片路径写上就可以显示网络的图片了
final MyImageView myImageView = (MyImageView) findViewById(R.id.image_view);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//直接把网络的图片路径写上就可以显示网络的图片了
myImageView.setImageURL("https://pic.cnblogs.com/avatar/1142647/20170416093225.png");
}
});
最后别忘了添加访问网络的权限
<uses-permission android:name="android.permission.INTERNET"/>
效果图
压缩
这是比较简单的从网络获取照片,直接在ImageView上显示,但是你有没有考虑过如果网络的图片很大,已经超出了手机屏幕的大小,如果还是加载原图的话无疑是浪费内存,还有可能造成内存溢出,所以我们有必要对网络的图片进行压缩,下面就开始讲网络图片的压缩。
首先获取ImageView要显示的宽度和高度
/**
* 获取ImageView实际的宽度
* @return 返回ImageView实际的宽度
*/
public int realImageViewWith() {
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
ViewGroup.LayoutParams layoutParams = getLayoutParams();
//如果ImageView设置了宽度就可以获取实在宽带
int width = getWidth();
if (width <= 0) {
//如果ImageView没有设置宽度,就获取父级容器的宽度
width = layoutParams.width;
}
if (width <= 0) {
//获取ImageView宽度的最大值
width = getMaxWidth();
}
if (width <= 0) {
//获取屏幕的宽度
width = displayMetrics.widthPixels;
}
Log.e("ImageView实际的宽度", String.valueOf(width));
return width;
}
/**
* 获取ImageView实际的高度
* @return 返回ImageView实际的高度
*/
public int realImageViewHeight() {
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
ViewGroup.LayoutParams layoutParams = getLayoutParams();
//如果ImageView设置了高度就可以获取实在宽度
int height = getHeight();
if (height <= 0) {
//如果ImageView没有设置高度,就获取父级容器的高度
height = layoutParams.height;
}
if (height <= 0) {
//获取ImageView高度的最大值
height = getMaxHeight();
}
if (height <= 0) {
//获取ImageView高度的最大值
height = displayMetrics.heightPixels;
}
Log.e("ImageView实际的高度", String.valueOf(height));
return height;
}
然后是通过网络图片的大小计算要压缩的比率
/**
* 获得需要压缩的比率
*
* @param options 需要传入已经BitmapFactory.decodeStream(is, null, options);
* @return 返回压缩的比率,最小为1
*/
public int getInSampleSize(BitmapFactory.Options options) {
int inSampleSize = 1;
int realWith = realImageViewWith();
int realHeight = realImageViewHeight();
int outWidth = options.outWidth;
Log.e("网络图片实际的宽度", String.valueOf(outWidth));
int outHeight = options.outHeight;
Log.e("网络图片实际的高度", String.valueOf(outHeight));
//获取比率最大的那个
if (outWidth > realWith || outHeight > realHeight) {
int withRadio = Math.round(outWidth / realWith);
int heightRadio = Math.round(outHeight / realHeight);
inSampleSize = withRadio > heightRadio ? withRadio : heightRadio;
}
Log.e("压缩比率", String.valueOf(inSampleSize));
return inSampleSize;
}
获得压缩比率后,就可以进行压缩了
/**
* 根据输入流返回一个压缩的图片
* @param input 图片的输入流
* @return 压缩的图片
*/
public Bitmap getCompressBitmap(InputStream input) {
//因为InputStream要使用两次,但是使用一次就无效了,所以需要复制两个
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int len;
while ((len = input.read(buffer)) > -1 ) {
baos.write(buffer, 0, len);
}
baos.flush();
} catch (IOException e) {
e.printStackTrace();
}
//复制新的输入流
InputStream is = new ByteArrayInputStream(baos.toByteArray());
InputStream is2 = new ByteArrayInputStream(baos.toByteArray());
//只是获取网络图片的大小,并没有真正获取图片
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
//获取图片并进行压缩
options.inSampleSize = getInSampleSize(options);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(is2, null, options);
}
最后就是在setImageURL()的方法中把 Bitmap bitmap = BitmapFactory.decodeStream(inputStream); 改成下面的方法
Bitmap bitmap = getCompressBitmap(inputStream);
缓存
有时候提高运行效率和节省流量,经常会使用的缓存,数据缓存后就算没有网络都可以使用,下面就开始学习缓存吧,我这种缓存不是正规的缓存技术。
将setImageURL()方法改成如下,并增加两全局变量imagePath、isUseCache;
//是否启用缓存
public boolean isUseCache = false;
private String imagePath;
//设置网络图片
public void setImageURL(String path) {
imagePath = path;
if (isUseCache){
useCacheImage();
}else {
useNetWorkImage();
}
}
把之前setImageURL()的大部分功能放到useNetWorkImage()方法中,增加一个判断:是否缓存图片
//使用网络图片显示
public void useNetWorkImage(){
//开启一个线程用于联网
new Thread() {
@Override
public void run() {
try {
//把传过来的路径转成URL
URL url = new URL(imagePath);
//获取连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//使用GET方法访问网络
connection.setRequestMethod("GET");
//超时时间为10秒
connection.setConnectTimeout(10000);
//获取返回码
int code = connection.getResponseCode();
if (code == 200) {
Bitmap bitmap;
//获取网络输入流
InputStream inputStream = connection.getInputStream();
//判断是否使用缓存图片
if (isUseCache){
//因为InputStream要使用两次,但是使用一次就无效了,所以需要复制两个
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
} catch (IOException e) {
e.printStackTrace();
}
//复制新的输入流
InputStream is = new ByteArrayInputStream(baos.toByteArray());
InputStream is2 = new ByteArrayInputStream(baos.toByteArray());
//调用压缩方法显示图片
bitmap = getCompressBitmap(is);
//调用缓存图片方法
cacheImage(is2);
}else {
//调用压缩方法
bitmap = getCompressBitmap(inputStream);
}
//利用Message把图片发给Handler
Message msg = Message.obtain();
msg.obj = bitmap;
msg.what = GET_DATA_SUCCESS;
handler.sendMessage(msg);
inputStream.close();
} else {
//服务启发生错误
handler.sendEmptyMessage(SERVER_ERROR);
}
} catch (IOException e) {
e.printStackTrace();
//网络连接错误
handler.sendEmptyMessage(NETWORK_ERROR);
}
}
}.start();
}
创建一个方法用于根据传了的网址生成一个独一无二文件,之后会根据这个路径生成图片和查找是否有缓存图片
/**
* 根据网址生成一个文件名
* @return 文件名
*/
public String getURLPath() {
StringBuilder urlStr2 = new StringBuilder();
String[] strings = imagePath.split("\\/");
for (String string : strings) {
urlStr2.append(string);
}
Log.e("MyImageView","文件名:"+urlStr2.toString());
return urlStr2.toString();
}
根据生成的路径缓存图片
/**
* 缓存网络的图片
* @param inputStream 网络的输入流
*/
public void cacheImage(InputStream inputStream) {
try {
File file = new File(getContext().getCacheDir(), getURLPath());
FileOutputStream fos = new FileOutputStream(file);
int len;
byte[] buffer = new byte[1024];
while ((len = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.close();
Log.e("MyImageView","缓存成功");
} catch (IOException e) {
e.printStackTrace();
Log.e("MyImageView","缓存失败");
}
}
最后就可以直接使用缓存图片了
//使用缓存图片
public void useCacheImage() {
//创建路径一样的文件
File file = new File(getContext().getCacheDir(), getURLPath());
//判断文件是否存在
if (file != null && file.length() > 0) {
//使用本地图片
try {
InputStream inputStream = new FileInputStream(file);
//调用压缩方法显示图片
Bitmap bitmap = getCompressBitmap(inputStream);
//利用Message把图片发给Handler
Message msg = Message.obtain();
msg.obj = bitmap;
msg.what = GET_DATA_SUCCESS;
handler.sendMessage(msg);
Log.e("MyImageView","使用缓存图片");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}else {
//使用网络图片
useNetWorkImage();
Log.e("MyImageView","使用网络图片");
}
}
现在就可以使用缓存了,记得要吧isUseCache设置成true
//直接把网络的图片路径写上就可以显示网络的图片了
String url = "https://pic.cnblogs.com/avatar/1142647/20170416093225.png";
//设置成true才会启动缓存,默认是false
myImageView.isUseCache = true;
myImageView.setImageURL(url);
整篇MyImageView.java的代码
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class MyImageView extends ImageView {
private String imagePath;
//是否启用缓存
public boolean isUseCache = false;
public static final int GET_DATA_SUCCESS = 1;
public static final int NETWORK_ERROR = 2;
public static final int SERVER_ERROR = 3;
//子线程不能操作UI,通过Handler设置图片
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case GET_DATA_SUCCESS:
Bitmap bitmap = (Bitmap) msg.obj;
setImageBitmap(bitmap);
break;
case NETWORK_ERROR:
Toast.makeText(getContext(), "网络连接失败", Toast.LENGTH_SHORT).show();
break;
case SERVER_ERROR:
Toast.makeText(getContext(), "服务器发生错误", Toast.LENGTH_SHORT).show();
break;
}
}
};
public MyImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MyImageView(Context context) {
super(context);
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
//设置网络图片
public void setImageURL(String path) {
imagePath = path;
if (isUseCache){
useCacheImage();
}else {
useNetWorkImage();
}
}
//使用网络图片显示
public void useNetWorkImage(){
//开启一个线程用于联网
new Thread() {
@Override
public void run() {
try {
//把传过来的路径转成URL
URL url = new URL(imagePath);
//获取连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//使用GET方法访问网络
connection.setRequestMethod("GET");
//超时时间为10秒
connection.setConnectTimeout(10000);
//获取返回码
int code = connection.getResponseCode();
if (code == 200) {
Bitmap bitmap;
//获取网络输入流
InputStream inputStream = connection.getInputStream();
//判断是否使用缓存图片
if (isUseCache){
//因为InputStream要使用两次,但是使用一次就无效了,所以需要复制两个
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
} catch (IOException e) {
e.printStackTrace();
}
//复制新的输入流
InputStream is = new ByteArrayInputStream(baos.toByteArray());
InputStream is2 = new ByteArrayInputStream(baos.toByteArray());
//调用压缩方法显示图片
bitmap = getCompressBitmap(is);
//调用缓存图片方法
cacheImage(is2);
}else {
//调用压缩方法
bitmap = getCompressBitmap(inputStream);
}
//利用Message把图片发给Handler
Message msg = Message.obtain();
msg.obj = bitmap;
msg.what = GET_DATA_SUCCESS;
handler.sendMessage(msg);
inputStream.close();
} else {
//服务启发生错误
handler.sendEmptyMessage(SERVER_ERROR);
}
} catch (IOException e) {
e.printStackTrace();
//网络连接错误
handler.sendEmptyMessage(NETWORK_ERROR);
}
}
}.start();
}
//使用缓存图片
public void useCacheImage() {
//创建路径一样的文件
File file = new File(getContext().getCacheDir(), getURLPath());
//判断文件是否存在
if (file != null && file.length() > 0) {
//使用本地图片
try {
InputStream inputStream = new FileInputStream(file);
//调用压缩方法显示图片
Bitmap bitmap = getCompressBitmap(inputStream);
//利用Message把图片发给Handler
Message msg = Message.obtain();
msg.obj = bitmap;
msg.what = GET_DATA_SUCCESS;
handler.sendMessage(msg);
Log.e("MyImageView","使用缓存图片");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}else {
//使用网络图片
useNetWorkImage();
Log.e("MyImageView","使用网络图片");
}
}
/**
* 缓存网络的图片
* @param inputStream 网络的输入流
*/
public void cacheImage(InputStream inputStream) {
try {
File file = new File(getContext().getCacheDir(), getURLPath());
FileOutputStream fos = new FileOutputStream(file);
int len;
byte[] buffer = new byte[1024];
while ((len = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.close();
Log.e("MyImageView","缓存成功");
} catch (IOException e) {
e.printStackTrace();
Log.e("MyImageView","缓存失败");
}
}
/**
* 根据网址生成一个文件名
* @return 文件名
*/
public String getURLPath() {
StringBuilder urlStr2 = new StringBuilder();
String[] strings = imagePath.split("\\/");
for (String string : strings) {
urlStr2.append(string);
}
Log.e("MyImageView","文件名:"+urlStr2.toString());
return urlStr2.toString();
}
/**
* 根据输入流返回一个压缩的图片
*
* @param input 图片的输入流
* @return 压缩的图片
*/
public Bitmap getCompressBitmap(InputStream input) {
//因为InputStream要使用两次,但是使用一次就无效了,所以需要复制两个
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int len;
while ((len = input.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
} catch (IOException e) {
e.printStackTrace();
}
//复制新的输入流
InputStream is = new ByteArrayInputStream(baos.toByteArray());
InputStream is2 = new ByteArrayInputStream(baos.toByteArray());
//只是获取网络图片的大小,并没有真正获取图片
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
//获取图片并进行压缩
options.inSampleSize = getInSampleSize(options);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(is2, null, options);
}
/**
* 获得需要压缩的比率
*
* @param options 需要传入已经BitmapFactory.decodeStream(is, null, options);
* @return 返回压缩的比率,最小为1
*/
public int getInSampleSize(BitmapFactory.Options options) {
int inSampleSize = 1;
int realWith = realImageViewWith();
int realHeight = realImageViewHeight();
int outWidth = options.outWidth;
Log.e("网络图片实际的宽度", String.valueOf(outWidth));
int outHeight = options.outHeight;
Log.e("网络图片实际的高度", String.valueOf(outHeight));
//获取比率最大的那个
if (outWidth > realWith || outHeight > realHeight) {
int withRadio = Math.round(outWidth / realWith);
int heightRadio = Math.round(outHeight / realHeight);
inSampleSize = withRadio > heightRadio ? withRadio : heightRadio;
}
Log.e("压缩比率", String.valueOf(inSampleSize));
return inSampleSize;
}
/**
* 获取ImageView实际的宽度
*
* @return 返回ImageView实际的宽度
*/
public int realImageViewWith() {
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
ViewGroup.LayoutParams layoutParams = getLayoutParams();
//如果ImageView设置了宽度就可以获取实在宽带
int width = getWidth();
if (width <= 0) {
//如果ImageView没有设置宽度,就获取父级容器的宽度
width = layoutParams.width;
}
if (width <= 0) {
//获取ImageView宽度的最大值
width = getMaxWidth();
}
if (width <= 0) {
//获取屏幕的宽度
width = displayMetrics.widthPixels;
}
Log.e("ImageView实际的宽度", String.valueOf(width));
return width;
}
/**
* 获取ImageView实际的高度
*
* @return 返回ImageView实际的高度
*/
public int realImageViewHeight() {
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
ViewGroup.LayoutParams layoutParams = getLayoutParams();
//如果ImageView设置了高度就可以获取实在宽度
int height = getHeight();
if (height <= 0) {
//如果ImageView没有设置高度,就获取父级容器的高度
height = layoutParams.height;
}
if (height <= 0) {
//获取ImageView高度的最大值
height = getMaxHeight();
}
if (height <= 0) {
//获取ImageView高度的最大值
height = displayMetrics.heightPixels;
}
Log.e("ImageView实际的高度", String.valueOf(height));
return height;
}
}
使用网络图片的效果图
使用缓存图片的效果图
使用图片加载框架Glide
在这开源非常发达的时代,肯定会有大牛为我们做了个种各样的开源框架,根本不需要我们做这么复杂的工作,下面就简单使用图片加载框架Glide
在使用前要添加Glide的依赖库
compile 'com.github.bumptech.glide:glide:4.0.0'
刚才的条件不变,把点击事件的操作换成下面两行代码
String url = "https://pic.cnblogs.com/avatar/1142647/20170416093225.png";
Glide.with(MainActivity.this).load(url).into(myImageView);
是不是非常简单,有了这个开源库,你还愿意写那一大堆的代码吗,我想不会,更强大的是它已经有缓存功能,这一切它都帮你做好了。
加载网络图片的效果图
使用缓存的效果图
既然那么强大的开源库,我们就简单地了解它是如何使用的,先看看with()方法的源码,它可以接收6中参数,所以在各种情况下都能使用
public static RequestManager with(Context context) {
return getRetriever(context).get(context);
}
public static RequestManager with(Activity activity) {
return getRetriever(activity).get(activity);
}
public static RequestManager with(FragmentActivity activity) {
return getRetriever(activity).get(activity);
}
public static RequestManager with(android.app.Fragment fragment) {
return getRetriever(fragment.getActivity()).get(fragment);
}
public static RequestManager with(Fragment fragment) {
return getRetriever(fragment.getActivity()).get(fragment);
}
public static RequestManager with(View view) {
return getRetriever(view.getContext()).get(view);
}
然后是load()方法,虽然只有一个方法,但是所能做的事情却不少,比如我刚才只是传了一个String类型的,它就可以帮我加载了网络的图片,它还支持File(加载本地图片)、int(加载应用文件的源)、byte[](字节流)、Uri
public RequestBuilder<Drawable> load(@Nullable Object model) {
return asDrawable().load(model);
}
我们就试试加载应用的图片
Glide.with(MainActivity.this).load(R.mipmap.ic_launcher).into(myImageView);
效果图
最后是into()方法,就是把我们要显示的ImageView加载进去,那就大功告成了。
重复使用过程Glide-->with()-->load()-->into()
项目源代码:doi-tools-center
Android在ImageView上直接显示网络图片相关推荐
- Android之——史上最简单最酷炫的3D图片浏览效果的实现
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/48052709 如今,Android开发已经成为移动互联开发领域中一支不可或缺的力量 ...
- android 获取网络图片并在Imageview上显示
这个是我使用的图片...http://imgstore04.cdn.sogou.com/app/a/100520024/877e990117d6a7ebc68f46c5e76fc47a 布局中声明一个 ...
- Android调用系统摄像头拍照并显示在ImageView上
简介 现在市面上的apk只要涉及用户中心都会有头像,而且这个头像也是可自定义的,有的会采取读取相册选择其中一张作为需求照片,另一种就是调用系统摄像头拍照并获取即时照片,本博文就是讲述如何调用摄像头拍照 ...
- Android使用ImageView显示网络图片
本案例使用ImageView 简单的实现了网络图片的调用.当中注意事项.由于用到了网络,这里採用了HttpClient方法訪问网络联接,关于怎样使用,可參照文章 Android中使用HttpClien ...
- android canvas imageview,怎么把canvas的内容在imageview上显示
我想要把canvas的内容在imageview上显示出来,可是我不是很懂 imageview.draw (canvas);是做什么的,这是我的代码: public class Matrix exten ...
- android显示多个网络图片不显示,Android显示网络图片实例
本文实例讲述了Android显示网络图片的方法,分享给大家供大家参考.具体方法如下: 一般来说,在Android中显示一张网络图片其实是非常简单的,下面就是一个非常简单的例子: 步骤1: ① 创建你的 ...
- android gridview 计算器,用GridView显示得到的网络图片
想看效果图: 主要代码如下: package yc.get_image: import java.io.BufferedInputStream: import java.io.IOException: ...
- android ListView显示网络图片
研究了android两个礼拜,稍微有了点眉目,开始正式帮公司开发应用的时候,发现ListView没有现成的显示网络图片的类或方法,网上查了查也没找到好的解决方法.心一横,自己研究吧,现在把我的解决办法 ...
- android afinal 图片,android中使用afinal一行代码显示网络图片
public class DemoActivity extends FinalActivity { @ViewInject(id=R.id.imageView) ImageView imageView ...
最新文章
- OpenCV 对图片亮度增强或减弱
- android lcd调试 高通平台lcd调试深入分析总结(mipi和rgb接口)
- Linux中expect的命令的使用
- 这个 “少年黑客”,用黑科技守护独居老人
- 【转】托管函数的挂钩(完美版)
- 批量scp脚本——从多台机器拷贝文件
- qt oracle bindvalue,Qt Sql bindValue与%
- tomcat 页面图片 管理 服务器 配置
- SAP Spartacus User form属性的运行时字段明细
- php5.6 连接 oracle,XAMPP中PHP5.6.3连接Oracle
- .net httpwebrequest 并发慢_go语言并发之MPG模型
- 系统没有远程桌面,如何安装远程桌面
- Java Thread类最终同步的void join(long time_in_ms)方法,带有示例
- css 商城 两列_css大法之使用伪元素实现超实用的图标库(附源码
- linux安全加固_安全服务之安全评估与加固
- ldo和dcdc功耗_深度解析DCDC和LDO各自的原理和区别
- julia 使用修改后的pkg
- 面转栅格之ERROR 999999:执行函数时出错
- 使用HTML写一个简历表格
- Android Studio 4.2Previw版本编译错误提示Disable offline mode and rerun the build
热门文章
- yml配置文件特殊字符处理
- LabVIEW生成exe错误解决方案(生成时VI断开,该VI已设置为不保存程序框图)
- 海大12-13年编程题第1题:1.编程计算下面函数的值,其中x为实数,由键盘输入。(9分) y={-1 x<=-5 {(x-1)^2 -5<x<10 {1/x
- 软件测试面试“圣经”分享,满满的知识点
- unity关节(joint)讲解
- 第一财经周刊:互联网公司正在瓦解传统广告业
- 搜索引擎looka_Alook浏览器使用方法教程
- 现在的公司都在疯狂的玩着直播
- 交通时空大数据如何分析,我写了本书!
- mems加速度计的性能解答-传感器专题