【问题标题】:android : how to stop repeat in zoom in animationandroid:如何停止重复放大动画
【发布时间】:2017-07-14 05:06:10
【问题描述】:

以下是我的 zoom_in.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1"
        android:toYScale="1" >
    </scale>
</set>

视图放大三倍。我怎样才能做到一次呢

PS:android:repeatCount="1" 不工作。

编辑1:我的动画Util有加载动画如下

public static Animation loadAnimation(Context context, @AnimRes int id)
        throws NotFoundException {

    XmlResourceParser parser = null;
    try {
        parser = context.getResources().getAnimation(id);
        return createAnimationFromXml(context, parser);
    } catch (XmlPullParserException ex) {
        NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" +
                Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } catch (IOException ex) {
        NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" +
                Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } finally {
        if (parser != null) parser.close();
    }

现在我把它称为如下

zoomIn = loadAnimation(getContext(),
            R.anim.zoom_in);
view.startAnimation(zoomIn);

【问题讨论】:

  • 不提android:repeatCount='"1"怎么办
  • 还可以尝试在代码中添加AnimationListener 并在onAnimationEnd 方法中停止动画。
  • 如果我不提及重复计数,它会放大 3 倍。如果我输入重复计数,它也会重复 3 次。
  • 给我看你的java代码并尝试第二个选项..
  • @ELITE 请检查我的代码是否有任何错误?

标签: android android-layout android-animation


【解决方案1】:

将重复计数设置为 0

zoomIn = loadAnimation(getContext(), R.anim.zoom_in);
zoomIn.setRepeatCount(0);

AnimationListener 添加到zoomIn,如下所示

zoomIn.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        // clear animation here
        view.clearAnimation();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    尝试使用“set”尝试“objectAnimator”:

     <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1"
        android:toYScale="1"
        android:repeatCount="1" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多