Animation代码设置

本文深入探讨了在Android应用中使用补间动画的方法,包括透明度、旋转、尺寸伸缩和移动效果的实现,提供了完整的代码示例。

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

在代码中设置,android补间动画:

//【补间动画,纯代码,写法如下】


    private void initAnimation() {  


            //透明度控制动画效果 alpha  
            animation_alpha=new AlphaAnimation(0.1f,1.0f);  
            //第一个参数fromAlpha为 动画开始时候透明度  
            //第二个参数toAlpha为 动画结束时候透明度  
            animation_alpha.setRepeatCount(-1);//设置循环  
            animation_alpha.setDuration(5000);//设置时间持续时间为 5000毫秒  
             
			  

            // 旋转效果rotate  
            animation_rotate = new RotateAnimation(0, -720,  
                    RotateAnimation.RELATIVE_TO_SELF, 0.5f,  
                    RotateAnimation.RELATIVE_TO_SELF, 0.5f);  
              //第一个参数fromDegrees为动画起始时的旋转角度 //第二个参数toDegrees为动画旋转到的角度  
              //第三个参数pivotXType为动画在X轴相对于物件位置类型 //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置  
              //第五个参数pivotXType为动画在Y轴相对于物件位置类型 //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置  
            animation_rotate.setRepeatCount(-1);  
            animation_rotate.setDuration(5000);//设置时间持续时间为 5000毫秒  
             
			  

            //尺寸伸缩动画效果 scale  
            animation_scale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);  
            //第一个参数fromX为动画起始时 X坐标上的伸缩尺寸      
            //第二个参数toX为动画结束时 X坐标上的伸缩尺寸       
            //第三个参数fromY为动画起始时Y坐标上的伸缩尺寸      
            //第四个参数toY为动画结束时Y坐标上的伸缩尺寸    
            /*说明: 
                                以上四种属性值     
                  0.0表示收缩到没有  
                  1.0表示正常无伸缩      
                               值小于1.0表示收缩   
                               值大于1.0表示放大 
            */  
            //第五个参数pivotXType为动画在X轴相对于物件位置类型    
            //第六个参数pivotXValue为动画相对于物件的X坐标的开始位置  
            //第七个参数pivotXType为动画在Y轴相对于物件位置类型     
            //第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置  
            animation_scale.setRepeatCount(-1);  
            animation_scale.setDuration(5000);//设置时间持续时间为 5000毫秒  
             
			  

            //移动动画效果translate  
            animation_translate=new TranslateAnimation(-20f,300f,-20f,300f);  
            //第一个参数fromXDelta为动画起始时 X坐标上的移动位置      
            //第二个参数toXDelta为动画结束时 X坐标上的移动位置        
            //第三个参数fromYDelta为动画起始时Y坐标上的移动位置   
            //第三个参数toYDelta为动画结束时Y坐标上的移动位置   
            animation_translate.setRepeatCount(-1);//设置动画执行多少次,如果是-1的话就是一直重复  
            animation_translate.setDuration(5000);//设置时间持续时间为 5000毫秒  
              


            animationSet=new AnimationSet(true);  
             
			  

            animationSet.addAnimation(animation_alpha);//透明度  
            animationSet.addAnimation(animation_rotate);//旋转  
            animationSet.addAnimation(animation_scale);//尺寸伸缩  
            animationSet.addAnimation(animation_translate);//移动  
            image.startAnimation(animationSet);//开始播放  
        } 



//动画监听
		animationSet.seta...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值