Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Let's say an ImageView width and height is set to match_parent and wrap_content respectively in the layout file. Something like this:

Java
<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


Then we access it in the java file:

Java
ImageView image = (ImageView) findViewById(R.id.image);


Then we create an animation:

Java
Animation anim = new AlphaAnimation(0, 1);
anim.setAnimationListener(new AnimationListener() {
    @Override
        public void onAnimationStart(Animation animation) {
            // do nothing
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // start next activity here
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // do nothing
        }
}


Then we attach the animation in the ImageView:

Java
image.startAnimation(anim);


Now this will not work, right? Since I believe the ImageView is empty (does not have a height, so the animation will not work and the onAnimationEnd will never be called)

But when I added the following line, the onAnimationEnd works!

setImageBitmap(null)


Upon checking the dimension of the view, the height is set to 1px.

Now, does this mean Animation only works when the the view has at least 1px of dimension (for both width and height)?

I tried to trace Android source code but I got lost somewhere and wasn't able to comprehend what is going on in the View, ImageView and Animation classes.

Can anyone shed some light regarding this? Thanks in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900