zoukankan      html  css  js  c++  java
  • Android ListView item项 显示动画

    (1)使用LayoutAnimation

        所谓的布局动画,其实就是为ViewGroup添加显示动画效果,主要用过LayoutAnimationController来控制实现。LayoutAnimationController用于为一个Layout里面的控件,或者是一个ViewGroup里面的控件设置动画效果,可以在XML文件中设置,亦可以在Java代码中设置。

    注意:布局动画是在android布局发生变化时添加动画效果,layout动画在每次布局发生变化的时候系统调用的一个预加载动画效果,使用layout动画可以让布局的变化过度看起来更自然

      1. 通过创建xml文件,其中list_anim在res/anim/list_anim.xml:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <set xmlns:android="http://schemas.android.com/apk/res/android"
     3   android:interpolator="@android:anim/accelerate_interpolator"
     4   android:shareInterpolator="true" >
     5 
     6   <alpha
     7     android:duration="1000"
     8     android:fromAlpha="0.0"
     9     android:toAlpha="1.0" />
    10 
    11 </set>

      2. 为ListView的layoutAnimation创建list_anim_layout.xml:

    1 <?xml version="1.0" encoding="utf-8"?>
    2 <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    3     android:delay="2"
    4     android:animationOrder="normal"
    5     android:animation="@anim/list_anim"/>
    1 <ListView
    2       ...
    3       ...4       android:layoutAnimation="@anim/list_anim_layout"/>
    1 // 在代码中实现列表动画
    2         Animation animation = (Animation) AnimationUtils.loadAnimation(
    3           mContext, R.anim.list_anim);
    4         LayoutAnimationController lac = new LayoutAnimationController(animation);
    5         lac.setDelay(0.4f);  //设置动画间隔时间
    6         lac.setOrder(LayoutAnimationController.ORDER_NORMAL); //设置列表的显示顺序
    7         mListView.setLayoutAnimation(lac);  //为ListView 添加动画

    (2)通过 Adapter.getView() 方法

        通过getView(int position, View convertView, ViewGroup parent) 返回的 view,进行对其动画操作就可。

    e.g. :水平向上移动并翻转360度。

    1 ObjectAnimator.ofFloat(convertView, "translationY", 400, 0).setDuration(1000).start();
    2 ObjectAnimator.ofFloat(convertView, "rotationX", 360, 0).setDuration(1000).start();

    参考:Layout动画:在android布局发生变化时添加动画效果

    Android的Animation之LayoutAnimation使用方法

    Android 从布局动画引入ListView滑动时,每一Item项的显示动画

  • 相关阅读:
    paramiko使用
    requests防止中文乱码
    RESTful架构
    关于pandas
    echarts基础使用
    跨站请求伪造CSRF原理
    js将方法作为参数调用
    Newtonsoft.Json解析json字符串和写json字符串
    图片压缩
    sql去重
  • 原文地址:https://www.cnblogs.com/CharlesGrant/p/4992348.html
Copyright © 2011-2022 走看看