Android ApiDemos示例解析(127):Views->Layout Animation->2. List Cascade

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

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

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可以较慢的速度显示动画效果。


 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值