2012-02-01 47 views
0

我想在我的appwidget循环中使用动画。 我已经通过xml定义了我的翻译动画,并在'set'上添加了android:repeatMode =“restart”,但没有任何反应,动画只运行一次,然后停止。根据documentation它应该被推下。appwidget动画在无限循环

<set xmlns:android="http://schemas.android.com/apk/res/android" android:repeatMode="restart"> 
    <alpha android:fromAlpha="0" android:toAlpha="1" android:duration="2000" /> 
</set> 

回答

4

既然你只使用1个动画,你不需要使用<set>。集合用于多个动画。 试试这个:

<alpha xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromAlpha="0" 
    android:toAlpha="1" 
    android:duration="2000" /> 

,并在您的活动:

Animation newsAnim= AnimationUtils.loadAnimation(this, R.anim.news_animation); 
newsAnim.reset(); // reset initialization state 
newsAnim.setRepeatMode(Animation.RESTART); 
newsAnim.setRepeatCount(Animation.INFINITE); // Or a number of times 
TextView animatedText = (TextView) findViewById(R.id.lbl_animated); 
animatedText.startAnimation(newsAnim); 

这将调用你的动画,设置所需的时间/功能。 我已经注意到,循环动画的设置并不像这样容易。

编辑:如果你需要使用一个<set>明确,那么你就可以做到以下几点:

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate 
     android:fromXDelta="0%" android:toXDelta="0%" 
     android:fromYDelta="100%" android:toYDelta="-100%" 
     android:duration="15000" android:zAdjustment="bottom" 
     android:repeatMode="restart" 
     android:repeatCount="-1" /> 

    <scale 
     android:fromXScale="4" android:toXScale="1" 
     android:fromYScale="3" android:toYScale="1" 
     android:pivotX="50%" android:pivotY="50%" 
     android:duration="15000" 
     android:repeatMode="restart" 
     android:repeatCount="-1" /> 
</set> 

注意所有的动画的持续时间。如果你想要一致的动画,让它们保持一致。

希望这有助于。 您确定,

Nyllian

+0

谢谢。问题是我正在尝试对appwidget进行动画制作,而不是常规活动,因此我无权访问AnimationUtils。 – 2012-02-19 13:21:19