bindView中的AnimationDrawables用于自定义ListView适配器

时间:2011-12-08 03:04:40

标签: android listview animation android-widget imageview

我有一个使用ListActivity子类的自定义SimpleCursorAdapter。在我的newView()bindView()方法中,我尝试动态创建AnimationDrawable,具体取决于数据库数据。 ImageViews仅显示第一个drawable,而不显示动画。

@Override
public void bindView(View v, Context context, Cursor c) {
    Resources res = context.getResources();

    Drawable frame1 = null;
    if(tt.getDrawable() != null) frame1 = res.getDrawable(tt.getDrawable());

    ImageView icon = (ImageView) v.findViewById(R.id.idt_icon);

    AnimationDrawable transition = new AnimationDrawable();
    transition.addFrame(frame1, 500);
    transition.addFrame(res.getDrawable(R.drawable.sunny_thought), 1000);
    transition.start();
    icon.setImageDrawable(transition);

1 个答案:

答案 0 :(得分:1)

你可以试试这个

frameAnimation.setOneShot(false);

有时它应该是frameAnimation.stop();,然后是frameAnimation.start();