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.

  • 相关阅读:
    ARP 协议
    3GPP 5G UPF
    OpenStack v.s. Kubernetes
    C#- FTP递归下载文件
    C#- WinForm获取 当前执行程序路径的几种方法
    C#- 布署WinForm程序
    Delphi- 连接MySQL数据库BDE
    Delphi- 内置数据库的使用例子BDE
    CSS- 兼容样式记录
    Delphi- DLL操作
  • 原文地址:https://www.cnblogs.com/spring87/p/4626261.html
Copyright © 2011-2022 走看看