2016年2月28日 星期日

Animating

Animating
step1:
creat directory
res/transition/

step2:
crate a file under the res/transition/,name is details_window_enter_transition.xml


<?xml version="1.0" encoding="utf-8"?>
<transitionSet  xmlns:android="http://schemas.android.com/apk/res/android"
   android:transitionOrdering="together"
   android:duration="500">
   <fade xmlns:android="http://schemas.android.com/apk/res/android">
       <targets>
           <target android:excludeId="@android:id/statusBarBackground"/>
           <target android:excludeId="@android:id/navigationBarBackground"/>
       </targets>
   </fade>
   <slide android:slideEdge="top">
       <targets>
           <target android:targetId="@id/toolbar"/>
       </targets>
   </slide>


   <slide android:slideEdge="bottom">
       <targets>
           <target android:targetId="@id/detail_additional_pane"/>
       </targets>
   </slide>

</transitionSet >



Explain:

<targets>
           <target android:excludeId="@android:id/statusBarBackground"/>
           <target android:excludeId="@android:id/navigationBarBackground"/>
       </targets>

don’t want the animation apply on these two thing




<slide android:slideEdge="top">
       <targets>
           <target android:targetId="@id/toolbar"/>
       </targets>

mean slide in from the to ,the target is the @id/toolbar

step3:apply to the Apptheme
in the style file

because we just want this animaition just apply to the detail activity,so we cretae a new style

<style name="AppTheme.Details" parent="@style/AppTheme">
       <item name="android:windowContentTransitions">true</item>
       <item name="android:windowEnterTransition">@transition/details_window_enter_transition
       </item>
      
   </style>

step4:apply the AppTheme.Details at AndroidManifest

<activity
           android:name=".DetailActivity"
           android:label="@string/title_activity_detail"
           android:parentActivityName=".MainActivity"
           android:theme="@style/AppTheme.Details">


step5:change the code to call the start of detail activity


Intent intent = new Intent(this, DetailActivity.class)
                   .setData(contentUri);


           ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(this);
           ActivityCompat.startActivity(this, intent, activityOptions.toBundle());


**for the Mainactivity,only <item name="android:windowContentTransitions">true</item> is ok