2010-07-16 11 views
0

lorsque j'essaie d'animer la vue personnalisée (créée en code Java), il n'y a pas d'effet, l'animation ne démarre pas. Voici comment je fais cela:Animation personnalisée Voir la classe

final Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation); 
    final CustomView background = new CustomView(this); 
    background.setBackgroundResource(R.drawable.bg); 
    background.startAnimation(animation); 

CustomView étend ImageView.

Ce code ne démarre pas l'animation, j'ai également essayé avec ImageView, et ne fonctionne pas non plus.

L'animation ne fonctionne que lorsque j'obtiens View de findViewById (id).

Voici le code d'animation:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false" 
    > 
    <alpha 
     android:fromAlpha="0.0" 
     android:toAlpha="1.0" 
     android:duration="1000" 
     /> 
    <alpha 
     android:fromAlpha="1.0" 
     android:toAlpha="1.0" 
     android:startOffset="1000" 
     android:duration="6000" 
     /> 
    <alpha 
     android:fromAlpha="1.0" 
     android:toAlpha="0.0" 
     android:startOffset="7000" 
     android:duration="1000" 
     /> 
</set> 
+0

Pourriez-vous poster le code XML pour l'animation? –

+0

android: shareInterpolator = L'attribut "false" est inutile, mais j'ai été en train d'utiliser ce fichier à partir d'une autre animation, et j'ai oublié de le couper. – Fisher

Répondre

0

Problème résolu. J'ai trouvé que l'animation était en cours d'exécution, mais le vrai problème était dans ma classe View personnalisée, où j'ai oublié d'appeler super dans onAnimationStart et onAnimationEnd.

Questions connexes