vis*_*rma 6 android fragment android-animation android-transitions
我想用动画替换片段,但每次都必须是动态的,即它将从我点击屏幕的点开始,但fragmentTransaction.setCustomAnimations方法使用anim文件夹中定义的预定义动画,如下所示:
fragmentTransaction.setCustomAnimations(R.anim.bounce, R.anim.bounce);
Run Code Online (Sandbox Code Playgroud)
我创建ScaleAnimation了满足我需要的对象:
ScaleAnimation animation = new ScaleAnimation(fromX,ToX,fromY,toY,pivitX,pivotY);
animation.setDuration(500);
Run Code Online (Sandbox Code Playgroud)
fragmentTransaction.setCustomAnimations方法不接受scaleAnimation它只接受int.那么如何在替换片段时获得动态动画.
您可以创建自定义动画集并使用它们。
创建一个 .xml 文件并将其放入“res/anim”文件夹中,然后在代码中使用其资源 ID:
fragmentTransaction.setCustomAnimations(R.anim.your_animation, R.anim.your_animation);
Run Code Online (Sandbox Code Playgroud)
这是动画的示例:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXDelta="-10%p"
android:toYDelta="1%p"/>
<scale
android:duration="@android:integer/config_shortAnimTime"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0.98"
android:toYScale="0.98"/>
<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="-10%p"
android:fromYDelta="1%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:startOffset="@android:integer/config_shortAnimTime"
android:toXDelta="100%p"
android:toYDelta="5%p"/>
<scale
android:duration="@android:integer/config_shortAnimTime"
android:fromXScale="0.98"
android:fromYScale="0.98"
android:startOffset="@android:integer/config_shortAnimTime"
android:toXScale="0.9"
android:toYScale="0.9"/>
</set>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2594 次 |
| 最近记录: |