Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Owner and Founder. Opencart
Top Partners
In this blog, We are going to show you how to shared element Image transition works in application.
To make a screen transition animation between two activities that have a shared element:
android:transitionName
ActivityOptions.makeSceneTransitionAnimation()
Step 1: Add android:transitionName=”profile” in your ImageView
activity_main.java
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context="application.coderdna.imageanimation.MainActivity"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:transitionName="profile" app:srcCompat="@mipmap/ic_launcher" tools:layout_editor_absoluteX="164dp" tools:layout_editor_absoluteY="129dp" /> </LinearLayout> 1234567891011121314151617181920 <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context="application.coderdna.imageanimation.MainActivity"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:transitionName="profile" app:srcCompat="@mipmap/ic_launcher" tools:layout_editor_absoluteX="164dp" tools:layout_editor_absoluteY="129dp" /> </LinearLayout>
Step 2: Add below code on your onClickListener,
Intent intent = new Intent(view.getContext(), Main2Activity.class); View v = ((View) findViewById(R.id.imageView)); ActivityOptionsCompat options = ActivityOptionsCompat. makeSceneTransitionAnimation(MainActivity.this, v, "profile"); startActivity(intent, options.toBundle()); 12345 Intent intent = new Intent(view.getContext(), Main2Activity.class); View v = ((View) findViewById(R.id.imageView)); ActivityOptionsCompat options = ActivityOptionsCompat. makeSceneTransitionAnimation(MainActivity.this, v, "profile"); startActivity(intent, options.toBundle());
MainActivity.java
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.imageView).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(view.getContext(), Main2Activity.class); View v = ((View) findViewById(R.id.imageView)); ActivityOptionsCompat options = ActivityOptionsCompat. makeSceneTransitionAnimation(MainActivity.this, v, "profile"); startActivity(intent, options.toBundle()); } }); } } 123456789101112131415161718 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.imageView).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(view.getContext(), Main2Activity.class); View v = ((View) findViewById(R.id.imageView)); ActivityOptionsCompat options = ActivityOptionsCompat. makeSceneTransitionAnimation(MainActivity.this, v, "profile"); startActivity(intent, options.toBundle()); } }); }}
Step 3: Add android:transitionName=”profile” in your ImageView in Result Activity,
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:transitionName="profile" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:srcCompat="@mipmap/ic_launcher" tools:context="application.coderdna.imageanimation.Main2Activity" tools:showIn="@layout/activity_main2"> 12345678910 <ImageView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:transitionName="profile" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:srcCompat="@mipmap/ic_launcher" tools:context="application.coderdna.imageanimation.Main2Activity" tools:showIn="@layout/activity_main2">
Done, Now you have made your first shared element transition.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.
Osama
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.