glassraven glassraven - 8 months ago 42
Android Question

Android: Animations - how to determine the end of an xml file animation and start an AlphaAnim in java?

I have an animation(xml) file that sets an image view to appear like the credits of a movie:

<?xml version="1.0" encoding="utf-8"?>


android:interpolator="@android:anim/linear_interpolator" >

android:toYDelta="0%p" />


As you can see, the image stops "moving" when it gets full screen. This is ok.
My question is: how can I set a textView (hidden) visible when this IV reaches de end of the animation, so the text can be over the image?

The java code:

protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

mozart=(ImageView) findViewById(;


read=(TextView) findViewById(;
restart=(Button) findViewById(;

Animation moz= AnimationUtils.loadAnimation(this, R.anim.animation);

read.setText("Text to appear with other alphaAnimation");


public void onClick(View view) {
if (view == restart) {

Intent a = new Intent(this, MainActivity.class);



Is it possible? I've tried several aproaches, but I cant't figure out how to tell the program when the image is ready to "receive" the text. Thaks for the help

Answer Source

You have to add an animation listener to the animation like this

moz.setAnimationListener(new Animation.AnimationListener(){
public void onAnimationStart(Animation arg0) {
   //Do Something on start
public void onAnimationRepeat(Animation arg0) {
public void onAnimationEnd(Animation arg0) {

When the animation starts it will first pass through the onStart( this is where u can initialize variables for animation) ...

then if you have repetition in your animation onAnimationRepeat will be called.

When the Animation is finished the onAnimationEnd will be called. ( This is the part you are interested in)