android - 将XML动画android更改为动态代码

标签 android android-animation

我有这个动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator">
    <scale android:fromXScale="1.0" android:toXScale="2.0"
    android:fromYScale="1.0" android:toYScale="2.0"
    android:pivotX="50%p" android:pivotY="50%p"
    android:duration="2000" />
</set>

但我必须在我的代码中使其动态:

AnimationSet animSet = new AnimationSet(false);
animSet.setInterpolator(AnimationUtils.loadInterpolator(AddPhoto.this,
     android.R.anim.decelerate_interpolator));
ScaleAnimation zoom = new ScaleAnimation(1.0f, 1.0f, 2.0f, 2.0f);
   zoom.setDuration(2000);
  animSet.addAnimation(zoom);

但是不一样,我做错了什么?谢谢。

最佳答案

您忘记设置 PivotX 和 PivotY。使用以下 ScaleAnimator 构造函数

public ScaleAnimation (float fromX, float toX, float fromY, float toY, 
                       float pivotX, float pivotY)


 Parameters

 fromX  Horizontal scaling factor to apply at the start of the animation
 toX    Horizontal scaling factor to apply at the end of the animation
 fromY  Vertical scaling factor to apply at the start of the animation
 toY    Vertical scaling factor to apply at the end of the animation
 pivotX The X coordinate of the point about which the object is being scaled, 
            specified as an absolute number where 0 is the left edge. (This point
            remains fixed while the object changes size.)
 pivotY The Y coordinate of the point about which the object is being scaled, 
            specified as an absolute number where 0 is the top edge. (This point
            remains fixed while the object changes size.)

关于android - 将XML动画android更改为动态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8664950/

相关文章:

Java/Android : How to update org. apache.http 已弃用

java - Android从url写入json文件

android - NavigationView 中的滚动动画

安卓屏幕动画

android - fragment - 等到交易动画完成

android - UICC : Can I trust proactive TIMER MANAGEMENT?

java - android string array nullpointerexception 在旧的 android 版本上

java - 面向对象编程与抽象数据类型编程的区别(多态性)

带有翻转 CardView 的 Android RecyclerView

android - 动画后按钮单击不起作用