Starting Animationdrawable In Listview Items. When Are The Items Attached?
So I've been doing some reading for the past few hours and I understand that calling start() on an AnimationDrawable before the Drawable/ImageView is fully attached will not start
Solution 1:
According to the documentation, you must wait until the View
is attached to the window before starting animation. Therefor, you should add an OnAttachStateChangeListener
to the view that will execute when it has been attached, and start the animation from there.
ImageViewloadingImg= (ImageView)v.findViewById(R.id.image);
loadingImg.setBackgroundResource(R.drawable.progressdialog);
loadingImg.addOnAttachStateChangeListener(newView.OnAttachStateChangeListener() {
@OverridepublicvoidonViewAttachedToWindow(View v) {
AnimationDrawableloadingAnimation= (AnimationDrawable) v.getBackground();
loadingAnimation.start();
}
@OverridepublicvoidonViewDetachedFromWindow(View v) {
}
});
I've tried starting the animation in a Runnable
in the View
's post()
method, and that didn't work. The above method is the only way I've reliably been to have animation start in a ListView
.
Post a Comment for "Starting Animationdrawable In Listview Items. When Are The Items Attached?"