我的目标是通过在自定义ArrayAdapter中用新增加的列表项替换列表项来动画某些ListView项,而不必担心getView搞乱动画.
如果我使用convertView来避免膨胀新项目,动画的顺序会随机变化.
最佳答案
我所做的是在convertview上设置动画,然后在每个转换视图上停止动画.这样,如果转换视图是新的,则动画停止然后播放,如果在结束之前没有回收,则继续播放直到结束.
在您的适配器中,您将拥有以下内容:
@Override
public View getView(int position,View convertView,ViewGroup parent) {
final ViewHolder holder;
if(convertView == null) {
// setup holder
holder = new ViewHolder();
LayoutInflater Inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = Inflater.inflate(mResourceId,null);
holder.image = (ImageView) convertView.findViewById(R.id.row_image);
holder.headline = (TextView) convertView.findViewById(R.id.row_headline);
convertView.setTag(holder);
} else {
// get existing row view
holder = (ViewHolder) convertView.getTag();
}
// GetView is only called on new items
// so Now we stop the prevIoUs animation and start a new
holder.animation.stop(); // First you stop the animation
holder.animation = new animation(); // then you create new
holder.animation.start(); // then you start the animation.
原文地址:https://www.jb51.cc/android/430572.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。