zoukankan      html  css  js  c++  java
  • AndroidUI 视图动画-自定义动画效果 (Animation)

    如果Android提供的四种动画 效果 和混合动画效果 不能够 满足需求的话,可以使用自定义动画效果 ;

    新建一个类CustomAnimation 使其继承自 android.view.animation.Animation

    package com.rock.lo6customanimation;
    
    import android.view.animation.Animation;
    import android.view.animation.Transformation;
    
    public class CustomAnimation2 extends Animation {
    
    	private float controlWith;
    	private float controlHeight;
    	//自定义动画执行applyTransformation之前会先执行initialize方法
    	//在initialize方法中能获取调用者的长度和宽度,以及父级容器的长度和宽度
    	@Override
    	public void initialize(int width, int height, int parentWidth,
    			int parentHeight) {
    
    		// TODO Auto-generated method stub
    		super.initialize(width, height, parentWidth, parentHeight);
    		controlWith=width;
    		controlHeight=height;
    	}
    	
    	@Override
    	protected void applyTransformation(float interpolatedTime, Transformation t) {
    		//设置透明效果 ,并且使期透明效果 根据interpolatedTime的值进行变化
    		//t.setAlpha(interpolatedTime);
    		
    		//根据矩阵设置旋转效果
    		//三个参数degress:旋转的度数,px:X轴开始位置,py:Y轴开始位置
    		//t.getMatrix().setRotate(interpolatedTime*360, controlWith/2, controlHeight/2);
    		
    		//使用按钮进行左右摇头(Y轴不动,使按钮进行左右来回移动)
    		t.getMatrix().setTranslate((float)Math.sin(interpolatedTime*50)*50, 0);
    		super.applyTransformation(interpolatedTime, t);
    	}
    }


    调用:

    <Button
            android:id="@+id/btnCustom2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/btnCustomAnim"
            android:layout_centerVertical="true"
            android:layout_marginRight="35dp"
            android:text="@string/btnCustom2" />


    findViewById(R.id.btnCustom2).setOnClickListener(new OnClickListener() {
    			
    			@Override
    			public void onClick(View v) {
    				CustomAnimation2 custom2=new CustomAnimation2();
    				custom2.setDuration(2000);
    				v.startAnimation(custom2);
    				
    			}
    		});


  • 相关阅读:
    Oracle一次可以查询多个表的结果的方法
    nagios+logstash实时监控java日志(一)
    原 ELK+Filebeat集中式日志解决方案(centos7)
    关于系统运维监控规范的几点建议和思考
    web文件管理系统和日志实时监控工具
    [运维]ELK实现日志监控告警
    阿里云服务器 发送邮箱 STMP 25端口 465端口问题 Javamail 25被禁用
    Elasticsearch5.6搭建及拼音中文混合搜索实现
    ELK pipeline
    图解Elasticsearch中的_source、_all、store和index属性
  • 原文地址:https://www.cnblogs.com/raphael5200/p/5114790.html
Copyright © 2011-2022 走看看