【问题标题】:How to load a circular appcompat actionbar logo using glide如何使用 glide 加载圆形 appcompat 操作栏徽标
【发布时间】:2016-08-09 08:19:44
【问题描述】:

到目前为止,我已经完成了以下操作,如果我省略了圆形图像创建部分,它可以正常工作,但我必须在操作栏中显示一个圆形图像

这是我到目前为止所尝试的,任何帮助将不胜感激

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()
                        {

                        }
                    });

【问题讨论】:

    标签: android android-actionbar android-actionbar-compat android-glide


    【解决方案1】:

    找不到办法,换了毕加索,改代码如下

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多