0

我正在 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;
}
4

0 回答 0