列表视图项 滚动时动画停止

2022-09-03 05:36:46

我试图为每个项目显示一个简单的动画,但是当我滚动时,动画停止了。滚动结束后,动画将再次开始。见下图。ProgressBarListViewProgressBar

Link
(资料来源:axgig.com


答案 1

您必须在 getView() 中使用动画并为转换设置动画查看示例:

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    StructureArticles item = getItem(position);
    if (convertView == null) {
        convertView = G.inflater.inflate(R.layout.adapter_articles, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.fill(this, item, position);
    Animation animationListView = AnimationUtils.loadAnimation(context, R.anim.scale_fade_in);
    convertView.startAnimation(animationListView);

    return convertView;
}

答案 2

我在我的适配器中使用了这种语法,问题解决了!

public class AdapterDownload extends ArrayAdapter<StructDownload> {

public AdapterDownload(ArrayList<StructDownload> array) {
    super(G.context, R.layout.item_layout, array);
}


private static class ViewHolder {

    public ViewHolder(View view)
    {

    }


    public void fill(final ArrayAdapter<StructDownload> adapter, final StructDownload item, final int position)
    {

    }
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {

}

}

谢谢。


推荐