I am implementing a BaseAdapter
and I have TranslateAnimation for a single list item.
The problem is that when scrolling down other views have the same offset.
Here is my implementation of the getView()
method:
@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;
}
My question is::
How can I keep the View
offset state for every ListView
item?