以前看到过一些给listview 中添加动画效果的库 ,具体是那个库一下子忘记了 ,所以现在有写博客的原因了,为了忘却的纪念。其实给listview中item添加动画很简单,这也是我从开源库 新闻快讯中看到的 使用的 ListViewAnimations开源库 创建一个继承AnimationAdapter类的CardsAnimationAdapter
public class CardsAnimationAdapter extends AnimationAdapter {
private final float mTranslationY = 400;private final float mRotationX = 15;
private final long mDuration = 400;
public CardsAnimationAdapter(BaseAdapter baseAdapter) {
super(baseAdapter);
}
@Override
protected long getAnimationDelayMillis() {
return 30;
}
@Override
protected long getAnimationDurationMillis() {
return mDuration;
}
@Override
public Animator[] getAnimators(ViewGroup parent, View view) {
return new Animator[] {
ObjectAnimator.ofFloat(view, "translationY", mTranslationY, 0),
ObjectAnimator.ofFloat(view, "rotationX", mRotationX, 0) };
}
}
其中的主要方法是 getAnimators 方法是添加动画的参数
AnimationAdapter animationAdapter = new CardsAnimationAdapter(
newAdapter);
是将BaseAdapter 作为参数传入进去
ListViewAnimations开源库 https://github.com/nhaarman/ListViewAnimations