2017-07-14 69 views
0

以下是我zoom_in.xml的android:如何停止变焦重复动画

<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); 
+0

如果您没有提及'android:repeatCount ='“1”' – ELITE

+0

如果在代码中添加'AnimationListener',并在'onAnimationEnd'方法中停止动画,该怎么办。 – ELITE

+0

如果我没有提及重复计数,它将放大3倍。如果我把重复计数也重复3次。 – MKY

回答

1

将重复计数设置为0

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

添加AnimationListenerzoomIn像下面

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) { 

    } 
}); 

希望这会有所帮助。

+0

嘿感谢它的作品! – MKY

0

insted的尝试 “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" />