2016-11-10 10 views
-2

Ich habe ein Problem mit einer Animation. Ich habe diesen Code geschrieben, aber nichts passiert.ImageView animieren

public void animate(View v){ 
    ImageView img = (ImageView) findViewByid(R.id.imageview); 
    img.animate().translationYBy(-1000f).setDuration(300); 
} 

Ich verwende wie diese Android Studio 2.2.2

Antwort

0

Versuchen kann es Hilfe für Sie

public void SlideToY() { 
    Animation slide = null; 
    slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, 
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 
      -5.0f, Animation.RELATIVE_TO_SELF, 0.0f); 

    slide.setDuration(2000); 
    slide.setFillAfter(true); 
    slide.setFillEnabled(true); 
    img.startAnimation(slide); 

    slide.setAnimationListener(new Animation.AnimationListener() { 

     @Override 
     public void onAnimationStart(Animation animation) { 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 


     } 

    }); 

} 
0

unten Code Versuchen für Imageview Animation sein. unter Beispiel 150 Pixel auf richtige Richtung (x cordinate)

Animation anim= new TranslateAnimation(xCurrentPos, xCurrentPos+150, yCurrentPos, yCurrentPos); 
anim.setDuration(1000); 
anim.setFillAfter(true); 
anim.setFillEnabled(true); 
animSurprise2Movement.setAnimationListener(new AnimationListener() { 

    @Override 
    public void onAnimationStart(Animation arg0) {} 

    @Override 
    public void onAnimationRepeat(Animation arg0) {} 

    @Override 
    public void onAnimationEnd(Animation arg0) { 
     xCurrentPos -= 150; 
    } 
}); 
imageview.startAnimation(anim); 
0

übersetzen Sie this lesen können über Android Ansicht Animationen zu lernen.

0

Versuchen Sie, diese Animation

public void animate(View v){ 
     ImageView img = (ImageView) findViewByid(R.id.imageview); 

     Animation anim = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
     anim.setInterpolator(new LinearInterpolator()); 
     anim.setRepeatCount(Animation.INFINITE); 
     anim.setDuration(4000); 

     img.startAnimation(anim); 
    } 
+0

Danke an alle, jetzt arbeitet mit meinem Code. Ich denke, ich habe einen Fehler in der .xml-Datei. – Unofficialpage

0

Sie verpassen die start() Methode.

public void animate(View v){ 
    ImageView img = (ImageView) findViewByid(R.id.imageview); 
    img.animate().translationYBy(-1000f).setDuration(300).start(); 
}