Android shared elements with Picasso

前提是你 提交于 2019-12-04 07:41:35

try to use transformation based on your need.

Transformation transformation = new Transformation() {

        @Override
        public Bitmap transform(Bitmap source) {
            int targetWidth = context.getResources().getDisplayMetrics().widthPixels - lessWidth;
            if (source.getWidth() > targetWidth) {
                double aspectRatio = (double) source.getHeight()
                        / (double) source.getWidth();
                int targetHeight = (int) (targetWidth * aspectRatio);
                Bitmap result = Bitmap.createScaledBitmap(source,
                        targetWidth, targetHeight, false);
                if (result != source) {
                    source.recycle();
                }
                return result;
            }
            return source;
        }

        @Override
        public String key() {
            return "transformation" + " desiredWidth";
        }
    };

this object can be used as below:

Picasso.with(context).load(strImageUrl).transform(transformation)
            .into(imageView, new com.squareup.picasso.Callback() {

                @Override
                public void onSuccess() {
                    Log.d("Picasso", "ImageLoadSuccess");                       
                }

                @Override
                public void onError() {
                    Log.d("PicassoHelper", "ImageLoadError");
                    if (imageView!=null&&defaultBitmap!=null) {
                        imageView.setImageBitmap(defaultBitmap);
                    }                       
                }
            });

hope this will help in your problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!