Ym--android 5.0 Learning Activity Transitions Animation

Source: Internet
Author: User

Objective


Activity Transition:

Three types of transition are available:

Enter : a enter The transition (animation) of
Exit : a exit The Transition (animation) determines how all views in an activity exit the screen.

shared elements : a shared element Transition (animation) determines the transition between two activities and how to share (them) views.


<span style= "FONT-SIZE:18PX;" ><span style= "font-family:arial, Helvetica, Sans-serif;" ></span><span style= "font-family:arial; line-height:26px; " ><span style= "color: #ff6666;" > supports these transitions for entry and exit animation </span><span style= "color: #333333;" >:</span></span><span style= "Color:rgb (51, 51, 51); Font-family:arial, Helvetica, Sans-serif; ></span></span> 
<span style= "font-family:arial, Helvetica, Sans-serif;" ><span style= "FONT-SIZE:18PX;" ><span style= "font-family:arial; line-height:26px; " >explode (decomposition) – Move the view in or out, </span><span style= "font-family:arial from the middle of the screen; line-height:26px; " >slide (swipe)-Move the view in or out, </span><span style= "font-family:arial from the edge of the screen; line-height:26px; " >fade (Fade in) – Add or remove views by changing the opacity of the on-screen view (effect) </span></span></span>


<span style= "font-family:arial, Helvetica, Sans-serif;" ><span style= "Font-size:18px;color: #ff6666;" > On the basis of the above animation can also add support for shared element transitions: (The effect of the shared element effect based on the decomposition animation on the basis of </span></span><span style= "Color:rgb (255, 102, 102); Font-family:arial, Helvetica, sans-serif;font-size:18px; >) </span>

Its role is to share two acitivity common elements, under Android 5.0 support the following effects:

Changebounds-Change the layout bounds of the target view

Changeclipbounds-Crop the target view boundary

Changetransform-Change the zoom scale and rotation angle of the target view

Changeimagetransform-Change the size and scale of the target image



Steps to use:

1. Set the animation ( two ways ):

1.1xml settings

When you define inherited material theme styles, use the android:windowcontenttransitions property to enable the content conversion (effect) of the window. You can also specify conversions for entering, exiting, and sharing elements:

<style name= "MyTheme" parent= "android:Theme.Material" >        <!--allows use of transitions--        <item name= " Android:windowcontenttransitions ">true</item>        <!--specify entry and exit Transitions-        <item name=" Android:windowentertransition "> @transition/explode</item>        <item name=" Android: Windowexittransition "> @transition/explode</item>        <!--specify shared element transitions--and        < Item Name= "Android:windowsharedelemententertransition" >            @transition/change_image_transform</item>        <item name= "android:windowsharedelementexittransition" >            @transition/change_image_transform</ Item></style>
define transition animations:

<transitionset xmlns:android= "Http://schemas.android.com/apk/res/android" >    <explode/>    < changebounds/>    <changeTransform/>    <changeClipBounds/>    <changeImageTransform/> </transitionSet>

1.2 Code settings

Allow the use of Transitionsgetwindow (). Requestfeature (window.feature_content_transitions);//Set an exit Transitiongetwindow ( ). Setexittransition (New Explode ());//new Slide ()  new Fade ()
window.setentertransition (): Set Enter animation

Window.setexittransition (): set exit effect

Window.setsharedelemententertransition (): set the Enter animation for a shared element

Window.setsharedelementexittransition (): set exit animations for shared elements


2.Activity Jump Method:

Go to exit animation jump:

StartActivity (Intent,              activityoptions.makescenetransitionanimation (this). Tobundle ());

Shared elements Jump:

To make a transition animation between two activities with a shared element:

1. Enable window content transitions in your theme

2. Specify transitions for shared elements in your theme style

3. Define your transition animations as XML resources

4. Use the Android:transitionname property to assign an identical name to the shared element in two layouts (name must not be written incorrectly)

5. Using the activityoptions.makescenetransitionanimation () method

Code:

Share Jump
Intent = new Intent (transitions.this, transitions4.class);                StartActivity (Intent, Activityoptions.makescenetransitionanimation (This,view, "ShareName"). Tobundle ());
Jump Target xml:

<?xml version= "1.0" encoding= "Utf-8"? ><absolutelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" match_parent "a            ndroid:layout_height= "Match_parent" android:background= "@android: Color/white" > <linearlayout            android:orientation= "Horizontal" android:id= "@+id/ll" android:background= "#2faaf3"            android:elevation= "2dip" android:layout_width= "fill_parent" android:layout_height= "200DP"/> <TextView Android:id= "@+id/btn_test" android:elevation= "8dip" android:padding= "10dip" an droid:layout_x= "300dip" android:layout_y= "175dip" Android:transitionname= "ShareName" Android Oid:layout_width= "50DP" android:layout_height= "50DP" android:background= "@drawable/myrect" Android:layout_below = "@+id/ll" Android:layout_alignpaRentend= "true" android:layout_marginright= "56DP"/></absolutelayout> 
If there are multiple shared elements:

Activityoptions options = Activityoptions.makescenetransitionanimation (This,        pair.create (View1, "agreedName1") ,        pair.create (View2, "agreedName2"));
Go try it!

Ym--android 5.0 Learning Activity Transitions Animation

Related Article

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.