Android的动画不重复 [英] Android animation does not repeat

查看:239
本文介绍了Android的动画不重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让简单的动画,将重复数次(或无限)。
看来,安卓的repeatCount 不起作用
! 下面是我的动画资源 /res/anim/first_animation.xml

 < XML版本=1.0编码=UTF-8&GT?;
<集
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:shareInterpolator =假
    安卓的repeatCount =无限
    >
    <规模
        机器人:插=@机器人:动画/ decelerate_interpolator
        机器人:时间=500
        机器人:fromXScale =1.0
        机器人:fromYScale =1.0
        机器人:toXScale =1.2
        机器人:toYScale =1.2
        机器人:pivotX =50%
        机器人:pivotY =50%
        机器人:fillAfter =FALSE/>
    <规模
        机器人:插=@机器人:动画/ accelerate_interpolator
        机器人:startOffset =500
        机器人:时间=500
        机器人:fromXScale =1.2
        机器人:fromYScale =1.2
        机器人:toXScale =1.0
        机器人:toYScale =1.0
        机器人:pivotX =50%
        机器人:pivotY =50%
        机器人:fillAfter =FALSE/>
< /集>
 

首先,它应该缩放图像从1.0到1.2的大小在500毫秒。
然后缩放回1.0在500毫秒。
下面是我如何使用它:

 动画firstAnimation = AnimationUtils.loadAnimation(这一点,R.anim.first_animation);
imgView.startAnimation(firstAnimation);
 

这让一周后结束。
它扩展了起来,然后按比例缩小答然后停止。

我怎样才能使这项工作按预期?

解决方案

更新:早在九月,2011一个Android工程师,在大多数情况下解决了这个问题。这是在XML忽略的属性现在的工作,除的repeatCount fillEnabled 这依然被忽略(故意的因为某些原因)。这意味着它仍然是不容易重复一个 AnimationSet 很遗憾。

有关详细信息,请参阅更新文档概述(解释了哪些属性忽略,这工作,并且被传递到儿童)。而对于更深入的了解什么 fillAfter fillBefore fillEnabled 其实也,看工程师的(切特·哈泽)关于它的博客文章<一个href="http://graphics-geek.blogspot.com/2011/08/mysterious-behavior-of-fillbefore.html">here.


原来的答案

要扩大在回答帕维尔和其他人:这是事实,在&LT;集&gt; 标签是可笑的马车。它可以正确地的repeatCount 和一些其他属性没有处理。

我花了几个小时搞清楚什么能做和不能处理,并在这里提交错误报告/问题:的发行17662

在汇总(此顾虑 AnimationSet S):

  

setRepeatCount()/安卓的repeatCount

     
    

此属性(以及REPEATMODE)不会在code或XML工作。这使得重复整套动画困难。

  
     

setDuration()/安卓:病程

     
    

在code工作的AnimationSet设置这个(覆盖儿童动画的所有持续时间),但不包含在XML标记时

  
     

setFillAfter()/安卓fillAfter

     
    

这工作在两种code和XML的标记。奇怪的是我得到它工作也无需设置fillEnabled为true。

  
     

setFillBefore()/安卓fillBefore

     
    

似乎没有任何效果/忽略这两个code和XML

  
     

setFillEnabled()/安卓fillEnabled

     
    

似乎没有任何效果/忽略这两个code和XML。我仍然可以得到fillAfter甚至没有工作,包括fillEnabled或设置fillEnabled为false。

  
     

setStartOffset()/安卓:startOffset

     
    

这仅适用于code,而不是XML。

  

I'm trying to make simple animation that would repeat several times (or infinitely).
It seems that android:repeatCount does not work!
Here is my animation resource from /res/anim/first_animation.xml :

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false"
    android:repeatCount="infinite"
    >
    <scale
        android:interpolator="@android:anim/decelerate_interpolator"
        android:duration="500"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="1.2"
        android:toYScale="1.2"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false" />
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:startOffset="500"
        android:duration="500"
        android:fromXScale="1.2"
        android:fromYScale="1.2"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false" />
</set>

First it should scale image from 1.0 to 1.2 size in 500 ms.
And then scale it back to 1.0 in 500 ms.
Here is how I'm using it:

Animation firstAnimation = AnimationUtils.loadAnimation(this, R.anim.first_animation);
imgView.startAnimation(firstAnimation);

It makes one cycle and then finishes.
It scales up, then scales down ans then stops.

How can I make this work as intended?

解决方案

Update: Back in Sep, 2011 an Android engineer fixed this issue for the most part. The attributes that were ignored in XML now work, with the exception of repeatCount and fillEnabled which are still ignored (on purpose for some reason). This means it still isn't easy to repeat an AnimationSet unfortunately.

For details please see the overview in the updated docs (explains which attributes are ignored, which work, and which are passed onto children). And for a deeper understanding of what fillAfter, fillBefore, and fillEnabled actually do, see the engineer's (Chet Haase) blog post about it here.


Original Answer

To expand upon answers by Pavel and others: it is true that the <set> tag is ridiculously buggy. It can't deal correctly with repeatCount and a number of other attributes.

I spent a few hours figuring out what it can and can't deal with and have submitted a bug report/issue here: Issue 17662

In summary (this concerns AnimationSets):

setRepeatCount() / android:repeatCount

This attribute (as well as repeatMode) does not work in code or XML. This makes repeating an entire set of animations difficult.

setDuration() / android:duration

Setting this on an AnimationSet in code WORKS (overrides all durations of children animations), but not when included in the tag in XML

setFillAfter() / android:fillAfter

This works in both code and XML for the tag. Strangely I have gotten it to also work without the need to set fillEnabled to true.

setFillBefore() / android:fillBefore

Seems to have no effect/ignored in both code and XML

setFillEnabled() / android:fillEnabled

Seems to have no effect/ignored in both code and XML. I can still get fillAfter to work even without including fillEnabled or setting fillEnabled to false.

setStartOffset() / android:startOffset

This works only in code and not XML.

这篇关于Android的动画不重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆