LayoutAnimationController

layoutanimation,顾名思义,是用来设置给viewgroup类型的animation,是子view来执行的。可以是

android:layoutAnimation="@anim/popinlayout" 
也可以是javacode的

viewgroup.setLayoutAnimation(layoutnaimationcontroller);

和Animation类似,Layout Animation也支持Animation Listener,具体的就不多说了。layoutanimation会在View Group第一次进行布局的时候执行一次。

具体来说,layoutanimation支持三个参数,

1,anim就不多说了,

2,animationOrder,这个是说子view按照什么顺序来执行anim,可以使normal(正常,0-n),reverse(反序,n-0),random。一般不要太乱的还是normal

3,delay,用于延迟的每个子view的动画开始动画持续时间的浮点数。越大间隔越长。0.3或者30%的字样。


另外,LayoutAnimationController包含一个内部类,LayoutAnimationController.AnimationParameters,这个类主要包括了count和index两个参数。这些参数用于计算每个单独的视图动画的开始时间。

ViewGroup.LayoutParams这个类大家都一定很熟悉的,主要是height和width。其中还有一个字段,就是LayoutAnimationController.AnimationParameters,Used to animate layouts


layoutanimation一般可以用在listview等adapterview中,显得比较炫一些。

比如:

    <ListView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:persistentDrawingCache="animation|scrolling" 
        android:layoutAnimation="@anim/scale_controller"
        >
    </ListView>


listview中还有一个viewgroup的属性,android:persistentDrawingCache 

Defines the persistence of the drawing cache. The drawing cache might be enabled by a ViewGroup for all its children in specific situations (for instance during a scrolling.) This property lets you persist the cache in memory after its initial usage. Persisting the cache consumes more memory but may prevent frequent garbage collection is the cache is created over and over again. By default the persistence is set to scrolling. 

 定义绘图的高速缓存的持久性。 绘图缓存可能由一个 ViewGroup 在特定情况下为其所有的子类启用,例如在一个滚动的过程中。 此属性可以保留在内存中的缓存后其初始的使用。 坚持缓存会消耗更多的内存,但可能会阻止频繁的垃圾回收是反复创建缓存。 默认情况下持续存在设置为滚动。

其属性值只有以下几种:

ConstantValueDescription
none 0x0 The drawing cache is not persisted after use.
animation 0x1 The drawing cache is persisted after a layout animation.
scrolling 0x2The drawing cache is persisted after a scroll.
all 0x3 The drawing cache is always persisted.


一般默认的有scrolling属性,我们在有layoutAnimation动画的时候添加上animation属性会更流通些。


参考:http://zhhx.blog.sohu.com/172724444.html


另有一篇关于帧动画的,http://blog.csdn.net/pipisky2006/article/details/6090753

  • 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、付费专栏及课程。

余额充值