Created
March 22, 2015 17:21
-
-
Save kosiara/8086a059d4ec8763ad68 to your computer and use it in GitHub Desktop.
Android: Add scene transition animation to your project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExplodeActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_explode); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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