首页 > 代码库 > activity fragment 转场动画

activity fragment 转场动画

v4 fragment

fragmentTransaction.setCustomAnimations(R.anim.push_left_in, R.anim.push_left_out, R.anim.push_left_in, R.anim.push_left_out);

fragment

入栈时,先从右边100%移动到左边0%

出栈时,从左边0% 移动到左外面-100%

第一个和第四个是控制进出的动画,中间两个不知表达什么,一直没搞明白

中间两个动画不起作用

 

4个item分别代表 

Activity A跳转到Activity B时Activity B进入动画;

Activity A跳转到Activity B时Activity A退出动画;

Activity B返回Activity A时Activity A的进入动画

Activity B返回Activity A时ActivityB的退出动画

 

 

push_left_in

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate android:fromXDelta="100%p" android:toXDelta="0"
		android:duration="3000" />

</set>

 push_left_out

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate android:fromXDelta="0" android:toXDelta="-100%p"
		android:duration="3000" />
</set>

 

 

 // fragment API LEVEL 13
  fragmentTransaction.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);

这个也是同样,第一个和第四个是控制进出的动画,中间两上不知表达什么,一直没搞明白

left_exit及right_enter这两个动画一直没出现过

fragment_slide_left_enter

<?xml version="1.0" encoding="utf-8"?>
<set xmlns: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="3000" />
    <objectAnimator
        android:interpolator="@android:interpolator/decelerate_quint"
        android:valueFrom="0.0" android:valueTo="1.0"
        android:valueType="floatType"
        android:propertyName="alpha"
        android:duration="3000" />
</set>

 

fragment_slide_left_exit

<?xml version="1.0" encoding="utf-8"?>
<set xmlns: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="3000" />
    <objectAnimator
        android:interpolator="@android:interpolator/decelerate_quint"
        android:valueFrom="1.0" android:valueTo="0.0"
        android:valueType="floatType"
        android:propertyName="alpha"
        android:duration="3000" />
</set>

 fragment_slide_right_enter

<?xml version="1.0" encoding="utf-8"?>
<set xmlns: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="3000" />
    <objectAnimator
        android:interpolator="@android:interpolator/decelerate_quint"
        android:valueFrom="0.0" android:valueTo="1.0"
        android:valueType="floatType"
        android:propertyName="alpha"
        android:duration="3000" />
</set>

 fragment_slide_right_exit

<?xml version="1.0" encoding="utf-8"?>
<set xmlns: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="3000" />
    <objectAnimator
        android:interpolator="@android:interpolator/decelerate_quint"
        android:valueFrom="1.0" android:valueTo="0.0"
        android:valueType="floatType"
        android:propertyName="alpha"
        android:duration="3000" />
</set>

 

再看activity

overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out); 

overridePendingTransition(R.anim.slide_in_bottom, R.anim.slide_out_bottom);

第一个是要打开的新页面的动画过程 ,第二个是要关闭的页面的动画过程

slide_in_bottom

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate android:fromYDelta="100%p" android:toYDelta="0"
            android:duration="2000"/>
	<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
            android:duration="2000" />
</set>

 slide_out_bottom

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate android:fromYDelta="0%p" android:toYDelta="0%p"
            android:duration="2000"/>
	<alpha android:fromAlpha="1.0" android:toAlpha="0"
            android:duration="2000" />
</set>