我希望实现一个类似于Google+列表视图的动画体验。当用户滑动列表视图时,列表中首先加载的每个项目都将启动动画效果。我尝试在getView方法中添加动画来为每个项目添加动画效果,但我想确认这种方式是否是一种好的方法,并且我是否需要扩展ListView类来完成此操作?因此,请给我一些建议或类似于Google+列表视图的示例。非常感谢:)
我希望实现一个类似于Google+列表视图的动画体验。当用户滑动列表视图时,列表中首先加载的每个项目都将启动动画效果。我尝试在getView方法中添加动画来为每个项目添加动画效果,但我想确认这种方式是否是一种好的方法,并且我是否需要扩展ListView类来完成此操作?因此,请给我一些建议或类似于Google+列表视图的示例。非常感谢:)
你不需要扩展ListView类。
这是一个Android库,实现了类似Google+的ListView动画。
它的工作方式是在适配器的getView
方法中,如果视图是新加载的,则对其进行动画处理。
(所以,它扩展了Adapter而不是ListView来制作动画。)
您还可以在sugared-list-animations-sample中的链接中下载示例应用程序的apk文件。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="@android:anim/decelerate_interpolator">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="100%" android:toYDelta="0%"
android:duration="400" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="@android:anim/decelerate_interpolator">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="-100%" android:toYDelta="0%"
android:duration="400" />
</set>
private int lastPosition = -1;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//Load your view, populate it, etc...
View view = ...;
Animation animation = AnimationUtils.loadAnimation(getContext(), (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
view.startAnimation(animation);
lastPosition = position;
return view;
}