SingleViewTransition
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
private static int count = 0;
private static final String transitionName = "image";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ImageView image = new ImageView(this);
image.setImageResource(R.mipmap.ic_launcher);
image.setTransitionName(transitionName);
final RelativeLayout container = new RelativeLayout(this);
container.setGravity((count++ % 2 == 0) ? Gravity.CENTER : Gravity.RIGHT);
container.addView(image);
setContentView(container);
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, image, transitionName);
startActivity(new Intent(MainActivity.this, MainActivity.class), options.toBundle());
}
});
}
}