android LayoutAnimation
来源:互联网 发布:网络实体店怎么开 编辑:程序博客网 时间:2024/05/21 14:01
LayoutAnimation 主要是实现viewgroup 子view改变的动画。OK先看一个效果
要实现这样的效果一般有两种方式:代码 和xml 配置两种
1.xml方式
先创建一个item_anim.xml的
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0" android:toAlpha="1" android:interpolator="@android:anim/decelerate_interpolator" android:duration="1000" ></alpha>
这里在啰嗦一下android interpolator的一些属性
AccelerateDecelerateInterpolator 在动画开始与结束的地方速率改变比较慢,在中间的时候加速
AccelerateInterpolator 在动画开始的地方速率改变比较慢,然后开始加速
AnticipateInterpolator 开始的时候向后然后向前甩
AnticipateOvershootInterpolator 开始的时候向后然后向前甩一定值后返回最后的值
BounceInterpolator 动画结束的时候弹起
CycleInterpolator 动画循环播放特定的次数,速率改变沿着正弦曲线
DecelerateInterpolator 在动画开始的地方快然后慢
LinearInterpolator 以常量速率改变
OvershootInterpolator 向前甩一定值后再回到原来位置
之后在创建一个layout_anim.xml
<?xml version="1.0" encoding="utf-8"?><layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="1.2" android:animationOrder="random" android:animation="@anim/item_anim"></layoutAnimation>
android:delay 表示动画播放的延时可以是百分比float 小数
android:animationOrder表示动画执行的顺序 总共有三个normal(按顺序)、reverse(反序)、random(随机)
android:animation 表示子控件要播放的动画
至此只需要将这个引用在布局中就好了。
如下
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" ><ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" android:layoutAnimation="@anim/layout_anim" ></ListView></RelativeLayout>
2.代码中实现
private void setAnimation(){ Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.item_anim); LayoutAnimationController controller = new LayoutAnimationController(animation); controller.setOrder(LayoutAnimationController.ORDER_NORMAL); controller.setDelay(0.3f); listView.setLayoutAnimation(controller); listView.startLayoutAnimation(); }
ok至此
- Android LayoutAnimation
- Android LayoutAnimation
- Android LayoutAnimation
- android LayoutAnimation
- Android --- layoutAnimation应用
- Android layoutAnimation简单应用
- Android LayoutAnimation 与 LayoutTransition
- 7.3 Android Framework - LayoutAnimation
- Android LayoutAnimation使用
- Android 动画之LayoutAnimation
- Android动画之LayoutAnimation
- Android layoutanimation的应用
- Android--LayoutAnimation介绍
- Android LayoutAnimation 与 LayoutTransition
- LayoutAnimation
- layoutAnimation
- Android - LayoutAnimation 动画效果 - 示例
- Android LayoutAnimation使用及扩展
- leetcode : subtree of another tree
- 问题寻找之表格内标签定位行数
- Safari浏览器无法播放视频资源(Java后台SSM架构)的解决方法
- Apache ZooKeeper简介
- UVA 1401 Remember the Word(DP+字典树Trie)
- android LayoutAnimation
- 编写简单的连接MongoDB数据库C++程序 && 解决编译C++程序时链接MongoDB动态库失败的问题
- 分布式dubbo + zookeeper
- BAT内部级别与薪资待遇
- c++入门教程(十六)
- linux tar命令的使用
- 关于setvbuf()函数的详解
- 【iOS】RxSwift入坑感想及建议
- C++多线程——AfxBeginThread