Tutorial :Animating custom View class



Question:

when i try to animate custom View (created in java code), there is no effect, animation doesn't start. This is how i do that:

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

CustomView extends ImageView.

This code doesn't start animation, i tried also with ImageView, and also doesn't work.

Animation works only when i am getting View from findViewById(id).

Here is animation code:

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


Solution:1

Problem solved. I found that animation in fact was executing, but real problem was in my custom View class, where i forget to call super in onAnimationStart and onAnimationEnd.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »