使用LayoutAnimationController

结合《第一行代码》的ListView的例子,在ListView的setAdapter方法之前,添加下面的代码:

AnimationSet set = new AnimationSet(true);

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

		animation.setDuration(300);

		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(300);
		
		set.addAnimation(animation);
		
		LayoutAnimationController controller = new LayoutAnimationController(set,0.5f);
		
		
		listView.setLayoutAnimation(controller);

这里使用里不止一种动画,所以使用了AnimationSet集合,实现后的效果(动画在途中没体现出来,把上面的代码用到你自己的ListView(或者其他的控件)中便得到体现)。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LayoutAnimationController是一个用于对ViewGroup中的子View进行动画控制的类。它主要用于在ViewGroup中添加、删除或重排子View时,对这些子View进行动画控制。 LayoutAnimationController可以通过以下方式创建: ``` LayoutAnimationController lac = new LayoutAnimationController(animation, delay); ``` 其中,animation表示子View的动画效果,delay表示动画延迟时间。 LayoutAnimationController支持以下属性: - order:子View动画的顺序,有三个可选值,分别为normal、reverse和random。 - delay:子View动画的延迟时间,单位为毫秒。 - animation:子View的动画效果。 - interpolator:子View动画的插值器。 以下是一个使用LayoutAnimationController进行子View动画的示例代码: ``` Animation animation = AnimationUtils.loadAnimation(this, R.anim.fade_in); LayoutAnimationController lac = new LayoutAnimationController(animation); lac.setDelay(0.5f); lac.setOrder(LayoutAnimationController.ORDER_NORMAL); LinearLayout container = findViewById(R.id.container); container.setLayoutAnimation(lac); for (int i = 0; i < 10; i++) { TextView textView = new TextView(this); textView.setText("Text " + i); container.addView(textView); } ``` 在上述代码中,我们先通过AnimationUtils加载了一个淡入动画效果,然后创建了一个LayoutAnimationController,并设置了一些属性,最后将LayoutAnimationController应用到LinearLayout容器中。最终,我们在容器中添加了10个TextView,当这些TextView被添加到容器中时,它们会按顺序依次显示,并且每个TextView都会执行一次淡入动画效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值