Search code examples
androidanimationonclickimageviewonclicklistener

Implementing makeSceneTransationAnimation in Android


I want to create transition animation for preveiwing picture like whatsapp or telegram, and i found very userful transition tutorial but i get stuck to implement in my apps. I start activity with this

ivProfile.setOnClickListener(v -> ImagePreview.start(context, contactResponse.getProfilePic()));

how to implement that code above in to action click below:

public void animate(View v){
    Intent i = new Intent(this, ImagePreview.class);
    String transition = getString(R.string.transition);
    View start = findViewById(R.id.iv_profile);
    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
            this, start, transition
        );
    ActivityCompat.startActivity(this, i, options.toBundle());
}

Solution

  • You can call like this, I don't think so any issue regarding this,

    make sure transition name(is in imageview which you have to apply transition animation) declared in ImagePreview Activity.

    ivProfile.setOnClickListener(v -> {
            Intent i = new Intent(this, ImagePreview.class);
            i.putExtra("IMG_URL", "YOUR_IMAGE_URL")
            String transition = getString(R.string.transition);
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                    this, ivProfile, transition
            );
            ActivityCompat.startActivity(this, i, options.toBundle());
        });