Example-SceneTransitionAnimation In Android?
activity_main.xml.
............................................................................................................
<LinearLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@color/colorAccent"> <ImageView android:id="@+id/image" android:layout_width="200dp" android:layout_height="200dp" android:scaleType="center" android:src="@drawable/log" /> </LinearLayout>
MainActivity.java
............................................................................................................
import android.annotation.TargetApi; import android.app.Activity; import android.app.ActivityOptions; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.View; import android.widget.ImageView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ImageView shared = (ImageView) findViewById(R.id.image); shared.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void onClick(View view) { ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, shared, ""); Intent intent = new Intent(MainActivity.this, SecondActivity.class); startActivity(intent, options.toBundle()); } }); } }
second_activity.xml
............................................................................................................
...........................................................................................................<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin android:background="@color/colorPrimaryDark"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Android Beginnerpoint tutorial" android:id="@+id/textView" android:textSize="35dp" android:textColor="@android:color/white"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" android:transitionName="sharedImage" android:layout_below="@+id/textView" android:layout_marginTop="54dp" /> </RelativeLayout>
SecondActivity.java
............................................................................................................
import android.annotation.TargetApi; import android.app.Activity; import android.app.ActivityOptions; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.View; import android.widget.Button; public class SecondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); final Button btn=(Button) findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void onClick(View v) { ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(SecondActivity.this, btn, ""); Intent intent = new Intent(SecondActivity.this, MainActivity.class); startActivity(intent, options.toBundle()); } }); } }
try this cod
0 comments