I have read a lot of tutorials about animation of the rows, but all of them describe how to animate the selected row. I managed to do it. But the there is a problem. When the row is removed with an animation, I remove data from the adapter and call notifyDataSetChanged(); The rows (below the removed row) go up without animation. How can I achieve the animation of these rows? I want them to slide up smoothly.
Remove the list item on item click, Hope this code will helpful for you
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
final int position, long id) {
// TODO Auto-generated method stub
Animation anim = AnimationUtils.loadAnimation(view.getContext(),
android.R.anim.slide_out_right);
anim.setDuration(500);
view.startAnimation(anim);
new Handler().postDelayed(new Runnable() {
public void run() {
strings.remove(position);
mAdapter.notifyDataSetChanged();
}
}, anim.getDuration());
}
});
UPDATE
Just keep in mind the architecture framework which works when the notifydatasetChanged() is called.
In your case, we have to animate the getView method ( which is to be called again on the action of the notifydatasetchanged). Here is the solution :
/**
* Hear strings is the data set
*/
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final String str = this.strings.get(position);
final Holder holder;
if (convertView == null) {
convertView = mInflater.inflate(
android.R.layout.simple_list_item_1, null);
convertView.setBackgroundColor(0xFF202020);
holder = new Holder();
holder.textview = (TextView) convertView
.findViewById(android.R.id.text1);
holder.textview.setTextColor(0xFFFFFFFF);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
holder.textview.setText(str);
Animation animation = null;
animation = new ScaleAnimation((float) 1.0, (float) 1.0, (float) 0,
(float) 1.0);
animation.setDuration(750);
convertView.startAnimation(animation);
animation = null;
return convertView;
}
Please check if it works and let me know if it was useful/helpful to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With