如果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. C++标准库和标准模板库

    转自原文http://blog.csdn.net/sxhelijian/article/details/7552499 C++强大的功能来源于其丰富的类库及库函数资源.C++标准库的内容总共在50个标 ...

  2. Oracle EBS-SQL (MRP-5):重起MRP Manager.sql

    UPDATE fnd_concurrent_processes SET process_status_code = 'K' WHERE process_status_code not in ('K', ...

  3. LoadRunner 技巧之THML 与 URL两种录制模式分析

    Loadrunner的Virtual User Generator 提供人脚本的录制功能,对于初学者来说,这大大的降低了编写脚本的门槛,loadrunner提供两种录制脚本的方式:Html_based ...

  4. [Leetcode][Python]53: Maximum Subarray

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 53: Maximum Subarrayhttps://leetcode.co ...

  5. poj 1742 coins_多重背包

    题意:给你N个种硬币,价值和数量,知道手表不大于m,问能组成(1~m)的价格有多少种情况 套套上次那题的模板直接就行了,http://blog.csdn.net/neng18/article/deta ...

  6. fafu 1568 Matrix(二分匹配+二分)

    Description:   You are given a matrix which <= n <= m <= ). You are supposed to choose n el ...

  7. 关于SQLSERVER去掉如何重复值的记录

    这个一个在日常工作中所遇到的问题 在此记录一下 dt_user_pay_record表 ID userid time money 1 2 2014-3-2 2 2 2 2015-3-2 33 3 2 ...

  8. autolisp 列表 resbuf

    有以下 list : (1 2 3 (4 5 6) "Properties" (("id" . 3) ("name" . "hel ...

  9. IIS中如何建立FTP服务

    文件传输协议 (FTP) 是一个标准协议,可用来通过 Internet 将文件从一台计算机移到另一台计算机.这些文件存储在运行 FTP 服务器软件的服务器计算机上.然后,远程计算机可以使用 FTP 建 ...

  10. JQuery(一)——初步总结

    JQuery其实早就看过相关的视频了,但是由于当时查的资料太少,理解的不够深刻,所以没有进行总结,这次回过头来又学习了,心里感觉理解了很多,因为BS的其它知识基本学习完了,而且有了一定程度的理解.相互 ...