Animation set fill and listener

1. I’ve found so far that:

android:setFillAfter=”true” is not accepted in xml

android:fillAfter=”true” is accepted but does not work

setFillAfter(true) in code does work, ie at the end of the animation the image does not revert to how it started the animation. An example:

		Animation display1 = AnimationUtils.loadAnimation(AnimActivity.this, R.anim.move_image1);
		display1.setFillAfter(true);

2. Another answer can be to set the image invisible in the on end listener of the animation.

anim1.setAnimationListener(new Animation.AnimationListener(){
		    @Override
		    public void onAnimationStart(Animation arg0) {
		    }           
		    @Override
		    public void onAnimationRepeat(Animation arg0) {
		    }           
		    @Override
		    public void onAnimationEnd(Animation arg0) {
				imageView.setVisibility(View.INVISIBLE);
		    }
		});

3. However I’ve found that if I use the on end listener to start a second animation, the setFillAfter is ignored, so the image reverts to its original position/look/size before doing the second animation. So far I have been able to avoid this problem by combining all animations into the same animation file.

This entry was posted in Android. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *