如何使用 glide 加载一个圆形的 appcompat actionbar logo
How to load a circular appcompat actionbar logo using glide
到目前为止,我已经完成了以下操作,如果我省略了圆形图像创建部分,它工作正常,但我必须在 actionbar 中显示圆形图像
这是我到目前为止所做的尝试,我们将不胜感激
Glide.with(mContext)
.load(doctorDetailsList.get(0).getDoc_imgurl().replace("200x200", Measuredwidth + "x" + Measuredwidth))
.placeholder(R.drawable.no_image)
.override(Measuredwidth, Measuredwidth)
.into(new Target<GlideDrawable>()
{
@Override
public void onLoadStarted(Drawable placeholder)
{
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable)
{
}
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation)
{
// GlideDrawable dr = resource;
Bitmap bitmap = ((com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable) resource).getBitmap();
String filename = doctorDetailsList.get(0).getDoc_imgurl().trim().substring(doctorDetailsList.get(0).getDoc_imgurl().trim().lastIndexOf("/") + 1);
filename = filename.replaceAll(".jpg", "");
int resID = getResources().getIdentifier(filename, "data", getPackageName());
Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), resID);
//Drawable d = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 200, 200, true));
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), icon);
circularBitmapDrawable.setCircular(true);
// GlideDrawable gd = new GlideDrawable(resource,)
getSupportActionBar().setLogo(circularBitmapDrawable);
}
@Override
public void onLoadCleared(Drawable placeholder)
{
}
@Override
public void getSize(SizeReadyCallback cb)
{
}
@Override
public void setRequest(com.bumptech.glide.request.Request request)
{
}
@Override
public com.bumptech.glide.request.Request getRequest()
{
return null;
}
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
@Override
public void onDestroy()
{
}
});
找不到方法,改用Picasso,改代码如下
Picasso.with(mContext)
.load(doctorDetailsList.get(0).getDoc_imgurl())
.resize(120, 120)
.centerCrop()
.placeholder(R.drawable.no_image)
.into(new com.squareup.picasso.Target()
{
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from)
{
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), bitmap);
circularBitmapDrawable.setCircular(true);
getSupportActionBar().setLogo(circularBitmapDrawable);
}
@Override
public void onBitmapFailed(Drawable errorDrawable)
{
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable)
{
}
});
到目前为止,我已经完成了以下操作,如果我省略了圆形图像创建部分,它工作正常,但我必须在 actionbar 中显示圆形图像
这是我到目前为止所做的尝试,我们将不胜感激
Glide.with(mContext)
.load(doctorDetailsList.get(0).getDoc_imgurl().replace("200x200", Measuredwidth + "x" + Measuredwidth))
.placeholder(R.drawable.no_image)
.override(Measuredwidth, Measuredwidth)
.into(new Target<GlideDrawable>()
{
@Override
public void onLoadStarted(Drawable placeholder)
{
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable)
{
}
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation)
{
// GlideDrawable dr = resource;
Bitmap bitmap = ((com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable) resource).getBitmap();
String filename = doctorDetailsList.get(0).getDoc_imgurl().trim().substring(doctorDetailsList.get(0).getDoc_imgurl().trim().lastIndexOf("/") + 1);
filename = filename.replaceAll(".jpg", "");
int resID = getResources().getIdentifier(filename, "data", getPackageName());
Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), resID);
//Drawable d = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 200, 200, true));
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), icon);
circularBitmapDrawable.setCircular(true);
// GlideDrawable gd = new GlideDrawable(resource,)
getSupportActionBar().setLogo(circularBitmapDrawable);
}
@Override
public void onLoadCleared(Drawable placeholder)
{
}
@Override
public void getSize(SizeReadyCallback cb)
{
}
@Override
public void setRequest(com.bumptech.glide.request.Request request)
{
}
@Override
public com.bumptech.glide.request.Request getRequest()
{
return null;
}
@Override
public void onStart()
{
}
@Override
public void onStop()
{
}
@Override
public void onDestroy()
{
}
});
找不到方法,改用Picasso,改代码如下
Picasso.with(mContext)
.load(doctorDetailsList.get(0).getDoc_imgurl())
.resize(120, 120)
.centerCrop()
.placeholder(R.drawable.no_image)
.into(new com.squareup.picasso.Target()
{
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from)
{
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), bitmap);
circularBitmapDrawable.setCircular(true);
getSupportActionBar().setLogo(circularBitmapDrawable);
}
@Override
public void onBitmapFailed(Drawable errorDrawable)
{
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable)
{
}
});