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

AndroidUI 视图动画-自定义动画效果 (Animation)的更多相关文章

  1. Java 给PPT添加动画效果(预设动画/自定义动画)

    PPT幻灯片中对形状可设置动画效果,常见的动画效果为内置的固定类型,即动画效果和路径是预先设定好的固定模板,但在设计动画效果时,用户也可以按照自己的喜好自定义动画动作路径.下面,通过Java后端程序代 ...

  2. 03.CSS动画-->自定义动画

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. UIVIewController自定义切换效果-b

      之前介绍动画时提过UIView的转场动画,但是开发中我们碰到更多的viewController的切换,ios中常见的viewcontroller切换有四种:模态视图,导航栏控制器,UITabBar ...

  4. Android 动画效果 及 自定义动画

    1. View动画-透明动画效果2. View动画-旋转动画效果3. View动画-移动动画效果4. View动画-缩放动画效果5. View动画-动画效果混合6. View动画-动画效果侦听7. 自 ...

  5. CSS3 自定义动画(animation)

    除了在之前的文章中介绍过的 CSS3 的变形 (transformation) 和转换 (transition) 外,CSS3 还有一种自由度更大的自定义动画,开发者甚至可以使用变形(transfor ...

  6. UI设计篇·入门篇·简单动画的实现,透明动画/旋转动画/移动动画/缩放动画,混合动画效果的实现,为动画设置监听事件,自定义动画的方法

    基本的动画构成共有四种:透明动画/旋转动画/移动动画/缩放动画. 配置动画的方式有两种,一种是直接使用代码来配置动画效果,另一种是使用xml文档配置动画效果 相比而言,用xml文档写出来的动画效果,写 ...

  7. 用POP动画编写带富文本的自定义动画效果

    用POP动画编写带富文本的自定义动画效果 [源码] https://github.com/YouXianMing/UI-Component-Collection [效果] [特点] * 支持富文本 * ...

  8. 微信小程序animation有趣的自定义动画

    这几天在看代码时遇到了一些问题:关于微信小程序的animation自定义动画自己没有系统的学习过 做动画需要我们将一个复杂的动作过程,拆解为一步一步的小节过程 微信中已经为我们写好了端口我们只需要实例 ...

  9. jQuery 自定义动画效果

    <!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js&qu ...

随机推荐

  1. PHP中的错误处理

    程序只要在运行,就免不了会出现错误!或早或晚,只是时间问题罢了. 错误很常见,比如Notice,Warning等等.此时一般使用set_error_handler来处理: <?php set_e ...

  2. PowerDesigner15在生成SQL时报错Generation aborted due to errors detected during the verification of the mod

    转载: http://blog.csdn.net/successful555/article/details/7582154 PowerDesigner中如何设置字符编码为GBK或者GB2312 ht ...

  3. 反调试技术(Delphi版)

    1.程序窗口句柄检测原理:用FindWindow函数查找具有相同窗口类名和标题的窗口,如果找到就说明有OD在运行//****************************************** ...

  4. jdk1.6下载页面

    http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-41940 ...

  5. hdu1003

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  6. asp.net中,我们使用ashx获取数据列表,在前端使用$.ajax()解析

    一直在想在asp.net中怎么才能向在java中那样用struts那样做页面请求. 当然asp.net mvc就是类似struts的东西吧,不过还没来得及学习. 今天就用ashx来接收页面请求,并调用 ...

  7. 查询本天气预报Web Services支持的国内外城市或地区信息

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://zhangkui.blog.51cto.com/1796259/497324 本文 ...

  8. 【 枚举 Enum 】循环 名称与值

      foreach (WeekDay c in (WeekDay [])Enum.GetValues(typeof(WeekDay ))) {Console.Write(String.Format(& ...

  9. Android应用开发基本流程及测试运行

    (1)Android App工程项目的创建 File—New—New Project 设置项目.程序包的名称 设置项目名称为MyDiary,程序包名为org.socrates.mydiary.acti ...

  10. JavaScript function函数种类(转)

    转自:http://www.cnblogs.com/polk6/p/3284839.html JavaScript function函数种类 本篇主要介绍普通函数.匿名函数.闭包函数 目录 1. 普通 ...