LayoutAnimationController

本文介绍如何在XML中使用LayoutAnimationController为布局中的控件设置动画效果,包括创建动画文件、配置布局文件及代码实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. LayoutAnimationController用于为一个Layout里面的控件或者是Viewgroup的控件设置动画效果。。

2.每一个控件都会有相同的动画效果

3.这些动画效果在不同的时间现实出来

4.LayoutAnimationController不仅可以在Layout里面实现也可以在代码中实现。。


怎么样在xml中使用LayoutAnimationController:

1在res/anim文件夹中创建一个新文件名为list-item-layout.xml文件

?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
 android:delay="2"
 android:animationOrder="normal" 
 android:animation="@anim/list_anim" />

2在布局文件当中添加如下配置

android:layoutAnimation=“@anim/list_item_layout


在代码中使用LayoutAnimationController

1.创建一个Animation对象,可以通过装载xml文件 也可以通过构造函数构造对象

2.使用如下代码创建LayoutAnimationController

LayoutAnimationController  lac=new LayoutAnimationController(animation);

3.设置控件显示的顺序

lrc.setOrder(LayoutAnimationController.ORDER_NORMAL)

4.为ListView设置LayoutAnimationController属性

listview.setLayoutAnimation(lac);

Animation animation = (Animation)AnimationUtils.loadAnimation(MainActivity.this, R.anim.list_anim);
   LayoutAnimationController lac = new LayoutAnimationController(animation);
   lac.setOrder(LayoutAnimationController.ORDER_NORMAL);
   lac.setDelay(0.5f);
   listView.setLayoutAnimation(lac);


public class LayoutAnimation2 extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mStrings));

        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(100);
        set.addAnimation(animation);

        LayoutAnimationController controller =
                new LayoutAnimationController(set, 0.5f);
        ListView listView = getListView();        
        listView.setLayoutAnimation(controller);
    }

    private String[] mStrings = {
        "Bordeaux",
        "Lyon",
        "Marseille",
        "Nancy",
        "Paris",
        "Toulouse",
        "Strasbourg"
    };
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值