zhu的工作日记:LayoutAnimation的简单使用(android)
来源:互联网 发布:剑网3捏脸数据详细 编辑:程序博客网 时间:2024/06/08 15:10
工作点滴,汇聚成雨
(LayoutAnimation的简单使用)
简单的说,LayoutAnimation就是帮父类管理子类集体动画的这么一个东东,例如listview里面有多个item,就可以按顺序的孩子设置统一的有顺序的动画效果(无序也可以),废话少说,操作最重要:
设置方法之一:xml
1.
res/layout/test.xml(为控件添加动画属性)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/gv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutAnimation="@anim/list_anim_layout"
android:numColumns="5" >
</GridView>
</LinearLayout>
重要的只有一句话: android:layoutAnimation="@anim/list_anim_layout",即开启动画,并指明那个动画,好了,来创建list_anim_layout.xml吧
2.
res/anim/list_anim_layout.xml(为集体动画做常规设置)
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
xmlns:android="http://schemas.android.com/apk/res/android"
<!-- 下一个item出现的时间,可以是百分百,可以是1 -->
android:delay="0.1"
<!-- item出现的顺序,normal是有序的,random是无序,还有其他-->
android:animationOrder="normal"
<!-- 这句又是重点,指定动画的效果-->
android:animation="@anim/push_right_in"/>
重要的还是只要一句话:android:animation="@anim/push_right_in,为每个item指定动画的效果,好了,又来个push_right_in.xml
3.
res/anim/push_right_in.xml(具体动画效果)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>
kekeke,搞定
设置方法之二:代码动态设置
1.为控件添加动画属性
gv= (GridView) findViewById(R.id.gv);
gv.setLayoutAnimation(getAnimationController()); //这句是重点
adapter = new ListViewAdapter(xxx);
gv.setAdapter(adapter);
2.为集体动画做常规设置(LayoutAnimation是开启集体动画功能,LayoutAnimationController 是控制集体动画,
protected LayoutAnimationController getController() {
// getAnimation()返回具体动画集,0.1f是下一个item出现的时机
LayoutAnimationController controller = new LayoutAnimationController(getAnimation(), 0.1f);
//ORDER_NORMAL是动画执行的顺序
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
return controller;
}
3.具体动画效果(详细动画介绍http://www.360doc.com/content/13/0102/22/6541311_257754535.shtml)
public AnimationSet getAnimation(){int duration=300;
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(duration);
set.addAnimation(animation);
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
animation.setDuration(duration);
set.addAnimation(animation);
return set;
}
kekeke,又搞定
- zhu的工作日记:LayoutAnimation的简单使用(android)
- zhu的工作日记:volley浅解(android)
- zhu的工作日记:安卓反编译工具使用教程(android)
- zhu的工作日记:带移动提示的seekBar的Demo(android)
- zhu的工作日记:图片三级缓存的工具类(android)
- zhu的工作日记:handler消息处理机制浅解(android)
- zhu的工作日记:指定日期往后延多少天(android)
- zhu的工作日记:设置app语言与系统语言(android)
- Android layoutanimation的应用
- LayoutAnimation的使用
- zhu的学习日记:shell脚本学习一(基础)
- Android-LayoutAnimation(布局动画)的学习
- android layoutAnimation属性简单介绍与使用
- hdu5833 Zhu and 772002 (高斯消元的简单应用)
- Android layoutAnimation简单应用
- LayoutAnimation简单使用
- Android LayoutAnimation使用
- Android的Animation之LayoutAnimation使用方法
- 寻找下一个较大元素 --- 利用栈
- 基础之菜单项的使用
- 第一周项目
- C提高——数组、数组数据类型、数组数据类型指针、多维数组本质等
- tomcat启动后访问应用超时问题
- zhu的工作日记:LayoutAnimation的简单使用(android)
- Java 编程思想第四版 笔记
- C语言的精髓-指针
- OpenJudge百炼习题解答(C++)--题2690:首字母大写
- 冒泡排序--BubbleSort
- 九度OJ 1541-1550(7/10)
- 解码和编码
- uva10558
- Python基础--快速改造:字符串