【发布时间】:2014-05-12 12:02:21
【问题描述】:
我正在实现BaseAdapter,并且我为单个列表项设置了 TranslateAnimation。
问题是向下滚动时其他视图的偏移量相同。
这是我对getView() 方法的实现:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
//initialization code
convertView.setTag(viewHolder);
} else {
viewHolder =(ViewHolder) convertView.getTag();
}
Animation animation;
switch (item.getAnimationDirection()) {
case AnimationDirection.HIDE:
animation = new TranslateAnimation(itemOffset, 0, 0, 0);
animation.setDuration(200);
animation.setFillAfter(true);
viewHolder.layoutToAnimate.setAnimation(animation);
item.setAnimationDirection(AnimationDirection.HIDDEN);
break;
case AnimationDirection.REVEAL:
itemOffset = viewHolder.remove.getWidth() + 20;
animation = new TranslateAnimation(0, itemOffset, 0, 0);
animation.setDuration(200);
animation.setFillAfter(true);
viewHolder.layoutToAnimate.setAnimation(animation);
item.setAnimationDirection(AnimationDirection.SHOWING);
break;
}
viewHolder.remove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (item.getAnimationDirection() == AnimationDirection.HIDDEN) {
item.setAnimationDirection(AnimationDirection.REVEAL);
notifyDataSetChanged();
}
}
});
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (item.getAnimationDirection() == AnimationDirection.SHOWING) {
item.setAnimationDirection(AnimationDirection.HIDE);
notifyDataSetChanged();
}
}
});
return convertView;
}
我的问题是::
如何为每个 ListView 项目保持 View 偏移状态?
【问题讨论】:
标签: android