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 ...
随机推荐
- JSON.parse()和JSON.stringify()的用法
JSON.parse()是用于从一个字符串中解析出json对象,如下所示 var str = '{"name":"flsummer","age&quo ...
- Oracle EBS-SQL (OM-5):检查订单事务处理类型.sql
SELECT HO.NAME OU ...
- HTML 5 <details> 标签
<details> 标签用于描述文档或文档某个部分的细节. <details> <summary>Copyright 2011.</summary> & ...
- Baidu Sitemap Generator插件使用图解教程
这两天因为百度对本博客文章收录更新很慢,一直在网络查找真正的原因和解决方法.最终发现了柳城开发的Baidu Sitemap Generator WordPress插件,最终效果如果还需要验证一段时间. ...
- java 获取特定天数的时间戳
public Timestamp strToDate(int type){ Timestamp time = null; DateFormat format2= new SimpleDateForma ...
- git备忘录
1.git: patch does not apply git apply --ignore-space-change --ignore-whitespace mychanges.patch 2.Ge ...
- Linux(gnu)环境动态链接库的搜索路径
摘自http://blog.csdn.net/saga1979/article/details/14161229 man ld.so(8)说,如果库依赖不包括“/”,那么它将按照下面的规则按顺序搜索: ...
- Android开发中目前流行控件和知识点总结
Android开发中目前流行控件和知识点总结 1.SlidingMenu 滑动菜单 应用案例:Facebook . Path 2.0 .人人.网易新闻 下载地址: https://github.c ...
- UITabBarItem
– finishedSelectedImage 返回选中时的图表 – finishedUnselectedImage 返回为选中时的图表 – setFinishedSelectedImage:with ...
- DropdownList的处理总结
创建一: List<SelectListItem> items = new List<SelectListItem>() { new SelectListItem(){Text ...