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);
    				
    			}
    		});


  • 相关阅读:
    android adb
    5 个免费的受欢迎的 SQLite 管理工具
    [Android]通过setImageURI设置网络上面的图片
    Android TextView实现长按复制文本功能的方法
    View工作原理(四)view的layout过程
    Anaroid WebView详解大全
    Android 如何在Eclipse中查看Android API源码以及support包源码
    关于Android的.so文件你所需要知道的
    AS问题解决系列3—iCCP: Not recognizing known sRGB profile(转)
    安卓App设计博文
  • 原文地址:https://www.cnblogs.com/raphael5200/p/5114790.html
Copyright © 2011-2022 走看看