android小记之Animation4种动画效果(贴上了GIF图)

本文介绍了Android中Animation的四种基本效果:AlphaAnimation(渐变透明)、ScaleAnimation(尺寸伸缩)、TranslateAnimation(平移)和RotateAnimation(旋转)。通过示例代码展示了如何在ListView中应用这些动画效果,提供了丰富的视觉展示。

 Animation是android的动画效果的组件,可以实现绚丽的翻页、ListView和GridView的展示。

 

这blog简单介绍一下4种动画效果方式:

1.  AlphaAnimation               控制渐变透明的动画效果    如图:


2.  ScaleAnimation               控制尺寸伸缩的动画效果 如图:

 


3.  TranslateAnimation        控制画面平移的动画效果  如图:

 


4.  RotateAnimation             控制画面角度变化的动画效果    如图:

 

 

具体的使用方法,直接上代码。注:我演示的代码在activity的onCreate()方法里面,直接加载了ListView的动画效果

 

        AnimationSet set = new AnimationSet(false);
        Animation animation = new AlphaAnimation(0,1);   //AlphaAnimation 控制渐变透明的动画效果
        animation.setDuration(500);     //动画时间毫秒数
        set.addAnimation(animation);    //加入动画集合
        
        animation = new TranslateAnimation(1, 13, 10, 50);  //ScaleAnimation 控制尺寸伸缩的动画效果
        animation.setDuration(300);
        set.addAnimation(animation);
        
        animation = new RotateAnimation(30,10);    //TranslateAnimation  控制画面平移的动画效果
        animation.setDuration(300);
        set.addAnimation(animation);
        
        animation = new ScaleAnimation(5,0,2,0);    //RotateAnimation  控制画面角度变化的动画效果
        animation.setDuration(300);
        set.addAnimation(animation);
        
        LayoutAnimationController controller = new LayoutAnimationController(set, 1);
        
        
        GridView gridView = (GridView) this.findViewById(R.id.gridview);
        gridView .setLayoutAnimation(controller);  //GridView 设置动画效果
        
        ListView listview= (ListView)this.findViewById(R.id.listview);
        listview.setLayoutAnimation(controller);   //ListView 设置动画效果


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值