Transition from a common item and Fresco do not work properly

I have two operations, each of which contains an image. I use Fresco to upload an image in one action, and Picasso to upload an image in another action. Here are the relevant parts of my code:

Image in the first activity

<com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/imageView102"
                android:transitionName="image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="9dp"
                android:layout_marginRight="9dp"
                android:layout_marginTop="10dp"
                fresco:actualImageScaleType="centerCrop"
                fresco:placeholderImage="@color/wait_color"
                fresco:placeholderImageScaleType="fitCenter"
                fresco:viewAspectRatio="1.33"
                android:layout_marginBottom="10dp" />

Image in the second activity

<uk.co.senab.photoview.PhotoView
        android:id="@+id/zoomable"
        android:transitionName="image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />

I use PhotoView in the second step to enlarge and reduce the image.

First activity

Uri uri = Uri.parse(photoUrl);
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                .setProgressiveRenderingEnabled(true)
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(image.getController())
                .build();
        image.setController(controller);
image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(ImageActivity.this, AlternateFullImageActivity.class);
                intent.putExtra("ID", photoId);
                intent.putExtra("photoUrl", photoUrl);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    ActivityOptionsCompat options = ActivityOptionsCompat.
                            makeSceneTransitionAnimation(ImageActivity.this, (View)image, "image");
                    startActivity(intent, options.toBundle());
                }
                else {
                    startActivity(intent);
                }
            }
        });

Second activity

Intent intent = getIntent();
        photoId = intent.getExtras().getString("ID");
        photoUrl = intent.getExtras().getString("photoUrl");

        Picasso.with(AlternateFullImageActivity.this)
                .load(photoUrl)
                .into(image);
        mAttacher = new PhotoViewAttacher(image);

The problem is that the transition is not smooth and very fast. I read here that I need to change the transition to ChangeBounds. How to change the transition to this and how to add a duration to this transition, for example, 1000 ms?

+4
2

, TransitionSet, , ChangeBounds. ...

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class DetailTransition extends TransitionSet {
    public DetailsTransition(int duration, int delay) {
        setOrdering(ORDERING_TOGETHER);
        addTransition(new ChangeBounds()).
                addTransition(new ChangeTransform()).
                addTransition(new ChangeImageTransform()).setDuration(duration).setStartDelay(delay).setInterpolator(new AnticipateOvershootInterpolator());
    }
}

/. ,

currentFragment.setSharedElementEnterTransition(new DetailsTransition(1000, 400));

getWindow().setSharedElementEnterTransition(new DetailsTransition(1000, 400));
+1

Fresco , .

:

https://github.com/facebook/fresco/tree/master/samples/transition

, setSharedElementEnterTransition() :

getWindow().setSharedElementEnterTransition(DraweeTransition.createTransitionSet(ScalingUtils.ScaleType.CENTER_CROP,ScalingUtils.ScaleType.FIT_CENTER));
getWindow().setSharedElementReturnTransition(DraweeTransition.createTransitionSet(ScalingUtils.ScaleType.FIT_CENTER,ScalingUtils.ScaleType.CENTER_CROP));
+5

Source: https://habr.com/ru/post/1626198/


All Articles