展会信息港展会大全

Android ApiDemos示例解析(127):Views->Layout Animation->2. List Cascade
来源:互联网   发布日期:2015-10-14 07:43:49   浏览:1872次  

导读:本例使用TranslateAnimation 给一个ListView的列表项向下逐步展开(Cascade)的动画效果,各种基本Animation可以参见Android ApiDemos示例解析...

本例使用TranslateAnimation 给一个ListView的列表项向下逐步展开(Cascade)的动画效果,各种基本Animation可以参见Android ApiDemos示例解析(3): App->Activity->Animation。

本例使用代码为ListView添加LayoutAnimation.

[java]

AnimationSet set = new AnimationSet(true);

Animation animation = new AlphaAnimation(0.0f, 1.0f);

animation.setDuration(50);

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(2000);

set.addAnimation(animation);

LayoutAnimationController controller

= new LayoutAnimationController(set, 0.5f);

ListView listView = getListView();

listView.setLayoutAnimation(controller);

AnimationSet set = new AnimationSet(true);

Animation animation = new AlphaAnimation(0.0f, 1.0f);

animation.setDuration(50);

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(2000);

set.addAnimation(animation);

LayoutAnimationController controller

= new LayoutAnimationController(set, 0.5f);

ListView listView = getListView();

listView.setLayoutAnimation(controller);

本例Cascade效果是通过TranslateAnimation实现的,本例使用的构造函数:

public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

fromXType: 指出fromXValue的模式,本例使用RELATIVE_TO_SELF,表示使用本View的宽度或是高度。RELATIVE_TO_PARENT为父View的宽度或是高度。ABSOLUTE 表示fromXValue使用绝对值。

fromXValue: 起始X坐标或当fromXType为RELATIVE_TO_PARENT或是RELATIVE_TO_SELF时表示相对于本View或父View的系数。本例向下展开,在X方向无动画,因此设为0.

toXType: 指出toXValue的模式,本例使用RELATIVE_TO_SELF,表示使用本View的宽度或是高度。RELATIVE_TO_PARENT为父View的宽度或是高度。ABSOLUTE 表示fromXValue使用绝对值。

toXValue: 结束X坐标或当fromXType为RELATIVE_TO_PARENT或是RELATIVE_TO_SELF时表示相对于本View或父View的系数。本例向下展开,在X方向无动画,因此设为0.

fromYType: 指出fromYValue的模式,本例使用RELATIVE_TO_SELF,表示使用本View的宽度或是高度。RELATIVE_TO_PARENT为父View的宽度或是高度。ABSOLUTE 表示fromYValue使用绝对值。

fromYValue: 起始Y坐标或当fromYType为RELATIVE_TO_PARENT或是RELATIVE_TO_SELF时表示相对于本View或父View的系数。

toYType: 指出toYValue的模式,本例使用RELATIVE_TO_SELF,表示使用本View的宽度或是高度。RELATIVE_TO_PARENT为父View的宽度或是高度。ABSOLUTE 表示fromXValue使用绝对值。

toYValue: 结束Y坐标或当fromYType为RELATIVE_TO_PARENT或是RELATIVE_TO_SELF时表示相对于本View或父View的系数。本例向下展开,值为1表示向下移动子View的高度。

将动画时间从100改成2000可以较慢的速度显示动画效果。

\

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港