Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android: Add scene transition animation to your project
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="EXPLODE ACTIVITY"/>
<ImageView
android:id="@+id/first_image"
android:transitionName="@string/explode_transition"
android:layout_width="wrap_content"
android:elevation="10dp"
android:background="@android:color/black"
android:scaleType="centerCrop"
android:src="@drawable/sample1"/>
</RelativeLayout>
public class ExplodeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_explode);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/first_image"
android:transitionName="explode_transition"
android:elevation="10dp"
android:background="@android:color/black"
android:scaleType="centerCrop"
android:src="@drawable/sample1"/>
</LinearLayout>
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
getWindow().setEnterTransition(new Fade());
getWindow().setExitTransition(new Fade());
setContentView(R.layout.main);
findViewById(R.id.first_image).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ExplodeActivity.class);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, v, v.getTransitionName());
startActivity(intent, options.toBundle());
}
});
}
}
//author: T.Konieczny
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.