安卓共享的元素与毕加索 [英] Android shared elements with Picasso

查看:277
本文介绍了安卓共享的元素与毕加索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让从列表中的图像运输于一体的活动细节的活动。

I'm trying to make an image transit from a list in one activity to a detail activity.

在具体活动的图像比在列表中,我使用的是毕加索从服务器检索的形象。

In the detail activity the image is bigger than in the list and I'm using Picasso to retrieve the image from the server.

问题是,我第一次推出了详细的活动,图像中转很好,但不能调整大小,也不居中。 当我回去时,图像会立即调整了,如果我再回到同样的细节活动,它按预期工作。

The problem is that the first time I launch the detail activity, the image transit well but is not resized nor centered. When I go back, the image is instantly resized, and if I come back to the same detail activity, it works as expected.

细节活动调用方法:

public static void launch(Activity activity, View transitionView,
                          StoreProduct storeProduct) {

    ActivityOptionsCompat options =
            ActivityOptionsCompat.makeSceneTransitionAnimation(
                    activity, transitionView, activity.getString(R.string
                            .transition_product_image));
    Intent intent = new Intent(activity, ProductDetailActivity.class);
    intent.putExtra(PARAM_STORE_PRODUCT, storeProduct);
    ActivityCompat.startActivity(activity, intent, options.toBundle());
}

毕加索图片加载中的详细活动:

The Picasso image loading in the detail activity:

Picasso.with(this).load(product.imageUrl).fit().centerInside()

感谢您的帮助

Thanks for your help

推荐答案

尝试根据您的需要使用转换。

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

此目的,可作为如下:

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.

这篇关于安卓共享的元素与毕加索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆