Android - ListAdapter - 行中的Animate ImageView在选择行时不会启动

时间:2013-08-29 15:16:41

标签: android animation android-listview android-arrayadapter

我在Android中使用自定义ArrayAdapter实现ListView。行布局包含TextView和ImageView,并根据行对象的状态,为ImageView设置动画。问题是,当我在所选行上启动动画时,它实际上不会启动动画,直到我选择另一行。下面是我的getView方法的简化版本:

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    View rowView = convertView;
    RowHolder holder = null;
    Item item = items.get(position);

    if(rowView == null)
    {
        rowView = _context.getLayoutInflater().inflate(R.layout.my_list, null);
        holder = new RowHolder();
        holder.title = (TextView)rowView.findViewById(R.id.title);
        holder.imageView = (ImageView)rowView.findViewById(R.id.imageView);
    }
    else
    {
        holder = (RowHolder)rowView.getTag();
    }

    holder.title.setText(item.title);

    if(item.status == ANIMATING)
    {
        holder.imageView.setVisiblity(View.VISIBLE);
        Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.button_rotate);

        holder.imageView.startAnimation(rotation);
    }
    else
    {
        holder.imageView.clearAnimation();
        holder.imageView.setVisibility(View.GONE);
    }

    return rowView;
}

0 个答案:

没有答案