我有这样的自定义转换类:
public class MyTransformation extends BitmapTransformation {
Context context;
public MyTransformation(Context context) {
super(context);
this.context = context;
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform,
int outWidth, int outHeight) {
return BitmapFactory.decodeResource(context.getResources(), R.drawable.viggi_rec);
}
@Override
public String getId() {
// Return some id that uniquely identifies your transformation.
return "MyTransformation";
}
}
这是用法:
try {
Glide.with(context)
.load(topList.get(i).getPhoto().get(0).getSrc())
.asBitmap()
.transform(new MyTransformation(context))
.into(homeViewHolder.imageView);
} catch (Exception e) {
System.out.print("Caught the exe");
e.printStackTrace();
}
我的问题是,图像没有加载,只是转换应用正确。当我清除转换时,图像被加载,一切都很好。
试试这个
try {
Glide.with(context)
.load(topList.get(i).getPhoto().get(0).getSrc())
.asBitmap()
.bitmapTransform(new MyTransformation(context))
.into(homeViewHolder.imageView);
} catch (Exception e) {
System.out.print("Caught the exe");
e.printStackTrace();
}to( imageView1 );