一个头像加载的类,用于异步获取资源,自定义View定义后加载

代码如下




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);
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值