如何实现谷歌+列表视图动画

7

我希望实现一个类似于Google+列表视图的动画体验。当用户滑动列表视图时,列表中首先加载的每个项目都将启动动画效果。我尝试在getView方法中添加动画来为每个项目添加动画效果,但我想确认这种方式是否是一种好的方法,并且我是否需要扩展ListView类来完成此操作?因此,请给我一些建议或类似于Google+列表视图的示例。非常感谢:)

2个回答

15

非常美丽 :) 非常感谢 - nguoitotkhomaisao

2
谷歌加号风格的列表视图(ListViews)因其在显示数据时展示的流畅动画而在Android上风靡一时。当用户向下滚动时,新条目会以动画效果出现在视图中,并且实际上看起来非常棒。这个文件名是up_from_bottom.xml
   <?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>

从顶部向下 down_from_top.xml
   <?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;
    }

http://kylewbanks.com/blog/Implementing-Google-Plus-Style-ListView-Animations-on-Android复制

这将应用于每次滚动,而不仅仅是像Google+中的列表视图中的新项目。 - SpyZip

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接