2017-07-14 3 views
0

Es folgt mein zoom_in.xmlandroid: wie in der Animation

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

die Ansicht ist, Zoom in drei Mal wiederholt in Zoom zu stoppen. wie kann ich es nur einmal machen

PS: android:repeatCount="1" funktioniert nicht.

EDIT 1: meine Animation Util haben laden Animation als

Folowing
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(); 
    } 

jetzt habe ich es wie folgt

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

Was ist, wenn Sie 'android nicht erwähnen: repeatCount = '" 1 "' – ELITE

+0

versuchen Sie auch 'AnimationListener' im Code und stoppen Sie die Animation in' onAnimationEnd 'Methode. – ELITE

+0

Wenn ich Wiederholungszählung nicht erwähne, zoomt es dreimal. und wenn ich wiederholen zähle es auch 3 mal wiederholen. – MKY

Antwort

1

Setzen Sie die Wiederholungszahl auf 0

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

AnimationListener zu zoomIn wie hinzufügen unter

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

    } 
}); 

Hope this helfen.

+0

hey danke es funktioniert! – MKY

0

Insted der Verwendung von "set" versuchen "objectAnimator" genannt haben:

<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" />