如果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. 重写 libev 的 EV_WIN32_HANDLE_TO_FD

    libev 的 EV_WIN32_HANDLE_TO_FD 默认实现是调用C库的  _open_osfhandle ,但这里有个问题是转换后,关闭 fd 就默认关闭了 handle.当它遇到 libc ...

  2. poj 1273 Drainage Ditches_最大流模版

    #include <iostream> #include<cstdio> #include<queue> #include<cstring> using ...

  3. SharePoint 2013的100个新功能之场管理

    一:改进的SPSite命令 SharePoint 2013中对SPSite PowerShell命令行做了改进提升,使网站集操作更简便.比如,一个新的参数“HostHeaderWebApplicati ...

  4. subllime text 创建可复用的代码片段

    对于前端工程师来讲,写一个html页面的基本结构是体力活,每次去拷贝一个也麻烦,sublime text 2 提供了一个很好的复用代码片段.下面介绍一下创建一个html5的代码片段的过程. 在菜单上点 ...

  5. #include <bitset>

    1 none();测试是否有越位 2 reset();全部清零 3 set(7, 0);把第7个字符改成0,操作二进制位 4 to_string();转换为字符串 5 to_ulong();转换为无符 ...

  6. #include <stack>

    1 pop(); 出栈 2 push(); 入栈 3 size(); 返回栈中元素个数 4 top(); 返回栈顶元素 使用栈,把十进制转换为二进制 #include <iostream> ...

  7. 移动端页面SEO优化需要注意的10个要点

    如今,移动互联网已经成为互联网组成的非常重要的一个分支,如果说以前对移动页面没有很规范的优化和高质量内容评判划分标准,但现在随着各大搜索引擎发布了移动建站指南,图文并茂的描述了如何提高移动站在百度质量 ...

  8. ChartControl简单的圆柱案例

    由于工作需要,最近学习了DevExpress控件中的ChartControl,并做了简单尝试,通过程序动态添加数据源到chartControl控件中,绘制了如下的条形图. 条形图的颜色等外观可在cha ...

  9. webapi拦截请求

    [AttributeUsage(AttributeTargets.Method)] public class WebApiSensitive : ActionFilterAttribute { pub ...

  10. Angular初级入门

    1:jquery :库 -一般是封装了一些方法 -我们去调用他的这些方法分 2:angular:框架 -框架是提供了一些规则或者模式 -我们是根据这一种规则或者模式去写代码 -然后接下来就由angul ...