在android中我试图使用Simple Adapter在ListView中显示基于其路径的图像。所以,我在我的数据库表中以字符串的形式存储了图像路径。现在我想在ListView中显示它们。怎么做?
答案 0 :(得分:1)
你可以写..
String photoUrl="your image url;
try{
if(photoUrl !=null) {
yourImageView.setImageURI(Uri.parse(photoUrl));
}
}catch (Exception e){
}
答案 1 :(得分:0)
如果您使用Glide / Picasso库进行图像加载,那将很容易。你只需要传递文件路径和休息过程滑行将自己做。
e.g。
Glide.with(imageView.getContext())
.load(url)
.placeholder(R.mipmap.place_holder)
.dontAnimate()
.into(imageView);
但请确保您的文件路径不为空并且是文件,否则您可能会遇到异常。
答案 2 :(得分:0)
尝试以下代码,它分两步读取文件
您可以在第二步调整缩放(请参阅注释)以匹配您的图像视图。如果您不需要缩放,您可以一步完成(然后忽略第一步)。
//Read file
Options options = new Options();
options.inJustDecodeBounds = true;
options.inDither = false; // for older API level
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.decodeFile(filename, options);
if(options.outWidth <= 0 || options.outHeight <= 0) {
return null;
}
// scale and load
options.inJustDecodeBounds = false;
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inSampleSize = 1; //Adjust scaling
Bitmap unscaledBitmap = BitmapFactory.decodeFile(filename, options);