Toggle animation for shared view elements during activity switching in Android (4.x compatibility Scheme)

Source: Internet
Author: User
<span id="Label3"></p>Also posted on my blog<p><p>Click here to enter</p></p>Begin<p><p>The previous article talked about using Google's appcompat-v7 to implement switching animations for shared view elements when the Activity was Switched. This article describes two two third-party scenarios that can be compatible with 4.X.</p></p><p><p>Prev: Toggle Animation of Shared view elements in Android when activity is toggled (more than 5.0)</p></p>Scenario One: Prelollipoptransition<p><p></p></p><p><p>First add this library dependency in the Build.gradle configuration file</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs matlab"><span class="hljs-cell">{ compile <span class="hljs-string">‘com.kogitune:pre-lollipop-activity-transition:1.0.0‘</span>}</span></code></pre></pre><p><p>The first is the Activity that starts</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java">findViewById(R.id.imageView).setOnClickListener(<span class="hljs-keyword">new</span> View.OnClickListener() { <span class="hljs-annotation">@Override</span> <span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">onClick</span>(View v) { <span class="hljs-keyword">final</span><span class="hljs-keyword">new</span> Intent(MainActivity.<span class="hljs-keyword">this</span>, SubActivity.class); ActivityTransitionLauncher.with(MainActivity.<span class="hljs-keyword">this</span>).from(v).launch(intent); }});</code></pre></pre><p><p>In the Activity that receives this Intent, write the following code:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs avrasm">@Overrideprotected void onCreate(Bundle savedInstanceState) { super<span class="hljs-preprocessor">.onCreate</span>(savedInstanceState)<span class="hljs-comment">;</span> setContentView(R<span class="hljs-preprocessor">.layout</span><span class="hljs-preprocessor">.activity</span>_sub)<span class="hljs-comment">;</span> ActivityTransition<span class="hljs-preprocessor">.with</span>(getIntent())<span class="hljs-preprocessor">.to</span>(findViewById(R<span class="hljs-preprocessor">.id</span><span class="hljs-preprocessor">.sub</span>_imageView))<span class="hljs-preprocessor">.start</span>(savedInstanceState)<span class="hljs-comment">;</span>}</code></pre></pre><p><p>Exiting an Animation's implementation</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java"><span class="hljs-keyword">private</span> ExitActivityTransition exitTransition;<span class="hljs-annotation">@Override</span><span class="hljs-keyword">protected</span><span class="hljs-keyword">void</span><span class="hljs-title">onCreate</span>(Bundle savedInstanceState) { <span class="hljs-keyword">super</span>.onCreate(savedInstanceState); setContentView(R.layout.activity_sub2); exitTransition = ActivityTransition.with(getIntent()).to(findViewById(R.id.sub_imageView)).start(savedInstanceState);}<span class="hljs-annotation">@Override</span><span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">onBackPressed</span>() { exitTransition.exit(<span class="hljs-keyword">this</span>);}</code></pre></pre><p><p>The welfare of the party: point I jump code address</p></p>Scenario Two: Activityoptionsics<p><p>No longer described in detail</p></p><p><p>The welfare of the party: point I jump code address</p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Toggle animation for shared view elements during activity switching in Android (4.x compatibility Scheme)</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.