zoukankan      html  css  js  c++  java
  • ListView 条目加载上滑下滑首尾缩放动画实现

    要实现这个效果,只需要再适配器getView之前,给每个条目的view设置相应的动画即可。

    首先需要2个动画的xml文件。

    在res下新建anim文件夹:(res/anim)

    第一个动画xml文件:

    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>
    

      

    在listview的适配器中使用定义的动画:

    代码如下:

    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

    If you are interested the animation,

    you can check out the full source on GitHub, or download the project and try it out.

  • 相关阅读:
    右值和move 与 forward
    C++11的chrono库,实现毫秒微秒级定时
    HDOJ 1176 免费馅饼(完全背包)
    HDU 1069 Monkey and Banana
    杭电 1003 Max Sum (动态规划)
    UVA ~ 514 ~ Rails (栈)
    UVA 679
    UVA11988 Broken Keyboard (a.k.a. Beiju Text)【数组模拟链表】
    Codeforces 845 C Two TVs
    codeforces 845A Chess Tourney
  • 原文地址:https://www.cnblogs.com/spring87/p/4626261.html
Copyright © 2011-2022 走看看