fragement切换动画效果的实现

标准动画:

fragementTransaction.setTransition(FragmentTransation.TRANSIT_FRAGMENT_CLOSE);
自定义动画:
fragementTransaction.setCustomAnimations();
通过属性动画定义切换的动画细节:
fragment_left_enter.xml
  1. <?xml version="1.0" encoding="utf-8"?>
    <setxmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
    android:interpolator="@android:interpolator/decelerate_quint"
    android:valueFrom="-100dp"android:valueTo="0dp"
    android:valueType="floatType"
    android:propertyName="translationX"
    android:duration="@android:integer/config_mediumAnimTime"/>
    <objectAnimator
    android:interpolator="@android:interpolator/decelerate_quint"
    android:valueFrom="0.0"android:valueTo="1.0"
    android:valueType="floatType"
    android:propertyName="alpha"
    android:duration="@android:integer/config_mediumAnimTime"/>
    </set>

     

fragment_left_exit.xml
  1. <?xml version="1.0" encoding="utf-8"?>
    <setxmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
    android:interpolator="@android:interpolator/decelerate_quint"
    android:valueFrom="0dp"android:valueTo="100dp"
    android:valueType="floatType"
    android:propertyName="translationX"
    android:duration="@android:integer/config_mediumAnimTime"/>
    <objectAnimator
    android:interpolator="@android:interpolator/decelerate_quint"
    android:valueFrom="1.0"android:valueTo="0.0"
    android:valueType="floatType"
    android:propertyName="alpha"
    android:duration="@android:integer/config_mediumAnimTime"/>
    </set>

     

fragment_pop_left_enter.xml
  1. <?xml version="1.0" encoding="utf-8"?>
    <setxmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
    android:interpolator="@android:interpolator/decelerate_quint"
    android:valueFrom="100dp"android:valueTo="0dp"
    android:valueType="floatType"
    android:propertyName="translationX"
    android:duration="@android:integer/config_mediumAnimTime"/>
    <objectAnimator
    android:interpolator="@android:interpolator/decelerate_quint"
    android:valueFrom="0.0"android:valueTo="1.0"
    android:valueType="floatType"
    android:propertyName="alpha"
    android:duration="@android:integer/config_mediumAnimTime"/>
    </set>

     

fragment_pop_left_exit.xml
  1. <?xml version="1.0" encoding="utf-8"?>
    <setxmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
    android:interpolator="@android:interpolator/decelerate_quint"
    android:valueFrom="0dp"android:valueTo="-100dp"
    android:valueType="floatType"
    android:propertyName="translationX"
    android:duration="@android:integer/config_mediumAnimTime"/>
    <objectAnimator
    android:interpolator="@android:interpolator/decelerate_quint"
    android:valueFrom="1.0"android:valueTo="0.0"
    android:valueType="floatType"
    android:propertyName="alpha"
    android:duration="@android:integer/config_mediumAnimTime"/>
    </set>
使用的时候:
fragmentTransaction.setCustomAnimations(
     R.animator.fragment_left_enter,
     R.animator.fragment_left_exit,
     R.animator.fragment_pop_left_enter,
     R.animator.fragment_pop_left_exit);

 

posted @ 2015-05-17 11:51  西北野狼  阅读(443)  评论(0编辑  收藏  举报