android 布局实现旋转动画效果

来源:互联网 发布:linux search文档 编辑:程序博客网 时间:2024/05/09 11:47

我们可以让一个组件动起来,也可以让几个组件一起动起来,其实就是给五大布局设置动画即可。

那么,如何给Linearlayout等布局设置绚丽的动画呢?

首先,要使用一个类,LayoutAnimationController。

其次,调用一个方法,layout.setLayoutAnimation(),并非是setAnimation().

实现方法有两种,一种是在xml中的linearLayout设置android:layoutAnimation=“@anim/layoutanimation_layout”。

一种是在代码中控制,使用LayoutAnimationController类。

第一种实现方式:

anim文件夹中的两个动画文件:

layoutanimation_layout:

<?xml version="1.0" encoding="utf-8"?><LayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"    android:animation="@anim/layoutanimation"    android:animationOrder="random"    android:delay="0.5" ></LayoutAnimation>

layoutanimation:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <alpha        android:duration="3000"        android:fromAlpha="0"        android:toAlpha="1" />    <rotate        android:duration="3000"        android:fromDegrees="0"        android:pivotX="50%"        android:pivotY="50%"        android:toDegrees="360" /></set>
第二种实现方式:

还是需要一个动画文件,如上,第二个文件,layoutanimation。

java代码:

//加载动画Animation anim = AnimationUtils.loadAnimation(this, R.anim.list_anim);lac = new LayoutAnimationController(anim);//设置顺序lac.setOrder(LayoutAnimationController.ORDER_REVERSE);//延时lac.setDelay(1);//布局设置动画layout.setLayoutAnimation(lac);




效果图:


通过这个例子证明动画效果却是非常耗费内存,需要展示绚丽的效果,则需要复杂的算法,cup的负担也就增大。

这里使用的是512M内存的设备测试,加载动画后他的内存使用率最高达到了83%,


而,没有加载动画,单单显示几行数据,他的内存使用率只有1%。差距是多么的大啊。



0 1