2010-11-11 8 views
26

J'ai besoin d'une animation pour une image dans mon application. L'image doit commencer à partir du coin supérieur gauche jusqu'au milieu de l'écran. La taille de l'image sera plus petite à l'étape initiale. En arrivant au milieu de l'écran, sa taille devrait augmenter (c'est-à-dire que la mise à l'échelle devrait avoir lieu). L'image ne doit pas revenir à sa position d'origine. Il devrait être placé au milieu de l'écran lui-même après l'animation.Scale & Translate animation

Quelqu'un peut-il s'il vous plaît aider.

Répondre

57

Veuillez trouver la réponse ici. Créez un dossier xml dans/res/anim et placez le code ci-dessous.

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/linear_interpolator"> 
    <scale android:fromXScale="0.0" android:fromYScale="0.0" 
      android:toXScale="1.0" android:toYScale="1.0" 
      android:duration="700" android:fillBefore="false" /> 
    <translate android:fromXDelta="-200" android:fromYDelta="-200" 
      android:duration="700" /> 
</set> 

Placez le code ci-dessous dans le fichier java:

Animation logoMoveAnimation = AnimationUtils.loadAnimation(this, R.anim.logoanimation); 
logoIV.startAnimation(logoMoveAnimation); 

logoanimation est le nom de mon fichier xml d'animation.

Merci à tous ceux qui ont essayé de répondre à ma question.

+1

hi Mathew, j'ai essayé une animation similaire mais l'image revient à la position d'origine et à l'échelle après la fin de l'animation. Comment éviter que l'image reprenne sa position et son échelle après la fin de l'animation? – Pravy

+0

@Pravy: - essayez d'ajouter ceci au XML >>> android: repeatCount = "0" – Nipuna

+4

@Pravy vous pouvez également essayer d'ajouter la ligne xml suivante: android: fillAfter = "true" –