代码如下
public class HeadPositionView {
private static final String TAG = "HeadPositionView";
private View view;
//头像地址
private String ulr;
private Context context;
private AvatarLoadCompleteCallback avatarLoadCompleteCallback;
public HeadPositionView(String ulr, Context context, AvatarLoadCompleteCallback avatarLoadCompleteCallback) {
this.ulr = ulr;
this.context = context;
this.avatarLoadCompleteCallback = avatarLoadCompleteCallback;
initView();
}
private void initView() {
if (view == null) {
view = View.inflate(context, R.layout.view_baidu_location, null);
}
LogUtil.d(TAG, "head url " + ulr);
CircleImageView headView = view.findViewById(R.id.iv_head_baidu);
RequestOptions options = new RequestOptions()
.error(R.drawable.default_custom_default);
Glide.with(context)
.load(ulr)
.apply(options)
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
headView.setImageDrawable(resource);
avatarLoadCompleteCallback.getView(view);
}
});
}
//Glide加载头像是异步调用,完成加载后,再生成bitMap在百度地图上绘制
public interface AvatarLoadCompleteCallback{
void getView(View view);
}
}