• 补间动画实现(tween)


    1.补间动画的概念:

    补间动画:仅仅须要开发人员设置好动画的開始与结束的关键帧 中间帧有喜用计算机补齐。

    2.种类:分为4种: ①alpha 透明度 ②alpha 透明度 ③translate 位置移动 ④rotate 旋转动画

    3.实现

      ① Java代码实现

       1)alpha 透明度 AlphaAnimation
       设置动画的透明度開始与结束 设置持续的时间。

       2.scale 比例缩放 ScaleAnimation
        设置缩放參照的中心轴(pivotyX,pivotyY)设置缩放開始的比例(x,y),结束的比例(x,y),

       3)translate 位置移动
           TranslateAnimation 设置动画的透明度開始(x,y)与结束(x,y) 设置持续的时间。

        4).rotate 旋转动画
         RotateAnimation 设置动画開始旋转的角度,结束时旋转的角度,并指定动画的持续时间,设置旋转的中心轴(pivotyX,pivotyY)
        5).综合应用:AnimationSet,set.addAnimation(a);

        ② XMl文件实现 结合代码 res/anim

        1).alpha 透明度<alpja></alpja>

        2).scale 比例缩放 <scale></scale>

        3).translate 位置移动<translate></translate>

        4).rotate 旋转动画 <rotate></rotate>

         综合应用:<set></set>  辅助类  AnimationUtils.loadAnimation(context, id);

    4.案例:

    1)创建xml文件进行4种方式的填写

        

    2)以rotate方式为例,能够:

    <?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
            android:fromDegrees="0" 
            android:toDegrees="1800"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="3000"
            android:fillAfter="true"></rotate>
    

    3)进行界面上的动画设置:

    public void clickRotate(View v) {
    		 rotateXml();
    		// rotateJava();
    
    	}
    
    	private void rotateXml() {
    		// 1.获取动画对象
    		Animation animation = AnimationUtils.loadAnimation(this,
    				R.anim.rotate_tween);
    		// 2.设置动画效果
    		imageView.setAnimation(animation);
    	}
    
    	public void rotateJava() {
    		// 1.创建动画的透明度对象
    		RotateAnimation rotateAnimation = new RotateAnimation(0, 1800, 0, 50);
    		// 2.为透明度动画对象设置值
    		rotateAnimation.setDuration(2000);
    		rotateAnimation.setFillAfter(true);
    		// 3.设置控件的动画
    		imageView.setAnimation(rotateAnimation);
    
    	}
    

    4)动画效果:

  • 相关阅读:
    ​DBEngines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
    深入了解 BTree 和 B+Tree 的区别
    exec详解
    javascript之property's attributes
    极客公园之李彦宏讲话要点
    C++之auto_ptr
    javascript之属性状态控制Method
    ARM寄存器简介
    linux之fcntl
    http之100continue
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4083104.html
Copyright © 2020-2023  润新知