zhu的工作日记:LayoutAnimation的简单使用(android)
2016-03-08 23:48
507 查看
工作点滴,汇聚成雨
(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,又搞定
(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,又搞定
相关文章推荐
- Android自定义控件ImageViwe(三)——随手指进行图片的缩放
- 这些年正Android - Traveling 第一章001
- 这些年正Android - Traveling 第一章001
- Android NDK环境搭建
- Android Studio Service 介绍
- android文件分段下载
- ViewTreeObserver.OnPreDrawListener()第一次无法监听或View第一次加载无图像;
- Android开发60条技术经验总结
- Android中自定义Dialog布局的两种方式比较
- 注册谷歌帐号以及用其他镜像解决android sdk的下载问题(已解决)
- 注册谷歌帐号以及用其他镜像解决android sdk的下载问题(已解决)
- 注册谷歌帐号以及用其他镜像解决android sdk的下载问题(已解决)
- android使用AIDL实现跨进程通讯(IPC)
- android开发时R文件丢失解决方案
- Android 快速开发系列 打造万能的ListView GridView 适配器
- Android中自定义样式与View的构造函数中四个参数的意义
- Android中使用AsyncTask实现异步加载
- AndroidStudio创建的LoginActivity分析
- Android开发环境配置
- android自学第二天