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);
}
});
AndroidUI 视图动画-自定义动画效果 (Animation)的更多相关文章
- Java 给PPT添加动画效果(预设动画/自定义动画)
PPT幻灯片中对形状可设置动画效果,常见的动画效果为内置的固定类型,即动画效果和路径是预先设定好的固定模板,但在设计动画效果时,用户也可以按照自己的喜好自定义动画动作路径.下面,通过Java后端程序代 ...
- 03.CSS动画-->自定义动画
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- UIVIewController自定义切换效果-b
之前介绍动画时提过UIView的转场动画,但是开发中我们碰到更多的viewController的切换,ios中常见的viewcontroller切换有四种:模态视图,导航栏控制器,UITabBar ...
- Android 动画效果 及 自定义动画
1. View动画-透明动画效果2. View动画-旋转动画效果3. View动画-移动动画效果4. View动画-缩放动画效果5. View动画-动画效果混合6. View动画-动画效果侦听7. 自 ...
- CSS3 自定义动画(animation)
除了在之前的文章中介绍过的 CSS3 的变形 (transformation) 和转换 (transition) 外,CSS3 还有一种自由度更大的自定义动画,开发者甚至可以使用变形(transfor ...
- UI设计篇·入门篇·简单动画的实现,透明动画/旋转动画/移动动画/缩放动画,混合动画效果的实现,为动画设置监听事件,自定义动画的方法
基本的动画构成共有四种:透明动画/旋转动画/移动动画/缩放动画. 配置动画的方式有两种,一种是直接使用代码来配置动画效果,另一种是使用xml文档配置动画效果 相比而言,用xml文档写出来的动画效果,写 ...
- 用POP动画编写带富文本的自定义动画效果
用POP动画编写带富文本的自定义动画效果 [源码] https://github.com/YouXianMing/UI-Component-Collection [效果] [特点] * 支持富文本 * ...
- 微信小程序animation有趣的自定义动画
这几天在看代码时遇到了一些问题:关于微信小程序的animation自定义动画自己没有系统的学习过 做动画需要我们将一个复杂的动作过程,拆解为一步一步的小节过程 微信中已经为我们写好了端口我们只需要实例 ...
- jQuery 自定义动画效果
<!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js&qu ...
随机推荐
- MYSQL 时间计算的 3 种函数
方法 1. 加法 adddate('date_expression',interval value type); 'date_expression' + interval value type; -- ...
- logcat错误日志
http://www.crifan.com/android_log_to_file/ http://www.iteye.com/problems/85431 http://www.cnblogs.co ...
- PHP单例模式编写
今天来点基础的设计模式: 如何利用单例模式实现一个数据库中间层 class Db{ static private $_instance; //当前数据库连接实例 static public funct ...
- 杭电oj 1009 FatMouse' Trade
Tips:本题采用贪心算法,类似于背包问题,关键在于读入数据之后,将数据按 J[i]/F[i] 从大到小排列即可. /**本程序主要采用贪心算法思想,类似于背包问题*/ #include<std ...
- 无组件客户端js图片压缩
<div class="free-upload"> <p>上传您的约会照片,一张合影.一张票据哦!</p> <div class=&quo ...
- MapReduce工作机制
MapReduce是什么? MapReduce是一种分布式计算模型,由Google提出,主要用于搜索领域,MapReduce程序本质上是并行运行的,因此可以解决海量数据的计算问题. MapReduce ...
- linux命令学习笔记
操作文件和文件夹: copy: $ cp file1 file2 $ cp -r dir1 dir2 move: $ mv file .. $ mv file dir/ rename: $ mv fi ...
- SqLiter
1.去重 select * from daydata where wtid||rectime in (select wtid||rectime from daydata group by wtid| ...
- (原) Jquery 判断移动设备是IOS / Android系统
var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > - ...
- HTML——JAVASCRIPT——关灯效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...