Reputation: 61
I have been trying to get frame animation to work recently.
I have struggled through the incorrect documentation example and have it working in an example application via the using onWindowFocusChanged to implement the start method.
My problem now lies in the fact I want to use it on a view that is controlled by getView in an array adapter.
Should this be possible?
ie
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView myImage =(ImageView)proximityView.findViewById(R.id.imgUserImage);
myImage.setBackgroundResource(R.drawable.animation);
AnimationDrawable frameAnimation = (AnimationDrawable) myImage.getBackground();
frameAnimation.start();
}
Upvotes: 1
Views: 1695
Reputation: 3971
I have listviews in a View Pager, and found that animations only started once the listview gained focus (touch eg). A solution I found to get by this is:
listView.requestFocus();
Upvotes: 1
Reputation: 2108
Posting the start function inside a separate runnable has helped me, though I still wouldn't guarantee it to work in all cases. Try this first.
View v = convertView;
final ImageView downloadButton = (ImageView) v.findViewById(R.id.imageview);
downloadButton.setBackgroundResource(R.anim.your_animation);
AnimationDrawable spinningImage = ((AnimationDrawable)downloadButton.getBackground());
downloadButton.post(new Runnable() {
@Override
public void run() {
AnimationDrawable spinningImage = ((AnimationDrawable)
downloadButton.getBackground());
spinningImage.start();
}
});
EDIT
Additionally since this is in a ListAdapter the problem could be your ListView not invalidating its children. In your main activity try running:
_listView.post(new Runnable(){
public void run(){
_listView.invalidateViews();
}
});
When you want the contents updated. Also maybe disable your caches.
_listView.setAnimationCacheEnabled(false);
_listView.setDrawingCacheEnabled(false);
Upvotes: 2