通过xml文件来设置动画
@android:anim/accelerate_interpolator: 越来越快
@android:anim/decelerate_interpolator:越来越慢
@android:anim/accelerate_decelerate_interpolator:先快后慢
@android:anim/anticipate_interpolator: 先后退一小步然后向前加速
@android:anim/overshoot_interpolator:快速到达终点超出一小步然后回到终点
@android:anim/anticipate_overshoot_interpolator:到达终点超出一小步然后回到终点
@android:anim/bounce_interpolator:到达终点产生弹球效果,弹几下回到终点
@android:anim/linear_interpolator:均匀速度。
——AccelerateInterpolator:动画从开始到结束,变化率是一个加速的过程。
——DecelerateInterpolator:动画从开始到结束,变化率是一个减速的过程。
——CycleInterpolator:动画从开始到结束,变化率是循环给定次数的正弦曲线。
——AccelerateDecelerateInterpolator:动画从开始到结束,变化率是先加速后减速的过程。
——LinearInterpolator:动画从开始到结束,变化率是线性变化。
设定动画延迟时间:android:startOffset="50"
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true"
android:startOffset="50"> <alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.0" /> </set>
alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0"
android:startOffset="200"
android:duration="1000"/> </set>
rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="-360"
android:pivotX="50%p"
android:pivotY="50%"
android:duration="1000"/> </set>
scale.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:toXScale="0"
android:fromYScale="1.0"
android:toYScale="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"/> </set>
translate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="50%"
android:toXDelta="100%"
android:fromYDelta="50%"
android:toYDelta="200%"
android:duration="2000"/> </set>
MainActivity.java
package com.kale.anim; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView; public class MainActivity extends Activity { ImageView iV; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iV = (ImageView)findViewById(R.id.imageView);
} public void buttonListener(View v) {
Animation anim = null;
switch (v.getId()) {
case R.id.alpha_button:
anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);
break;
case R.id.rotate_button:
anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);
break;
case R.id.scale_button:
anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scale);
break;
case R.id.translate_button:
anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate);
break;
default:
break;
} //设置开始动画
iV.startAnimation(anim);
}
}
通过工具类就能加载xml文件,这样就能使用xml文件了。最后贴上xml的界面文件。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" > <LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:orientation="vertical" > <Button
android:id="@+id/alpha_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonListener"
android:text="透明度改变" /> <Button
android:id="@+id/rotate_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonListener"
android:text="旋转动画" /> <Button
android:id="@+id/scale_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonListener"
android:text="缩放动画" /> <Button
android:id="@+id/translate_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="buttonListener"
android:text="移动动画" />
</LinearLayout> <ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:src="@drawable/ic_launcher" /> </RelativeLayout>
关于动画速率设置。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true">
……
</set>
example:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0"
android:startOffset="200"
android:duration="1000"/> </set>
代码中可以这样设置:
AnimationSet set = new AnimationSet(true);
set.setInterpolator(new DecelerateInterpolator());
通过xml文件来设置动画的更多相关文章
- Android中string.xml文件中设置部分字体颜色大小
1.在string.xml文件中: <string name="tips_all"><Data><![CDATA[清理进程:<font colo ...
- 如何在maven pom.xml文件中设置Java编译器版本
今天遇到一个问题: 在Eclipse中用maven创建一个新的web项目,然后再用maven update一下,则JDK版本自动变为1.5. 通过查找资料,终于发现maven编译器插件(Maven C ...
- 在AndroidManifest.xml文件中设置Android程序的启动界面方法
从网上搜集了一堆的Android代码,比如Android的Login程序和Android的Helloworld程序,但是却总不能正确运行一个正确的程序,郁闷了很久,终于在一次一次的测试后成功的在And ...
- UI设计篇·入门篇·简单动画的实现,为布局设置动画,用XML布置布局动画
不仅仅控件可以设置动画,一个布局也可以设置动画, 当给一个布局设置了动画的时候,这个布局里所包含的控件都会依赖执行这些动画. 为布局设置动画的实现步骤: 1.新建一个动画,设置需要实现的形式 2.新建 ...
- 006 Android XML 文件布局及组件属性设置技巧汇总
1.textview 组件文本实现替换(快速实现字符资源的调用) android 应用资源位置在 project(工程名)--->app--->res--->values 在stri ...
- pom.xml文件设置
一个相对完整的maven配置文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...
- Android 为PopupWindow设置动画效果
首先定义显示效果的动画文件: <?xml version="1.0" encoding="utf-8"?> <set xmlns:androi ...
- XML文件(1)--使用DOM示例
其他依赖字段/方法 // 书籍列表 private List<Book> bookList = new LinkedList<Book>(); /** * 根据xml文件,得到 ...
- Tomcat源码分析——SERVER.XML文件的加载与解析
前言 作为Java程序员,对于Tomcat的server.xml想必都不陌生.本文基于Tomcat7.0的Java源码,对server.xml文件是如何加载和解析的进行分析. 加载 server.xm ...
随机推荐
- application/json 四种常见的 POST 提交数据方式
四种常见的 POST 提交数据方式 HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 ...
- 利用openssl构建根证书-服务器证书-客户证书
利用openssl构建根证书-服务器证书-客户证书 OpenSSL功能远胜于KeyTool,可用于根证书,服务器证书和客户证书的管理 一.构建根证书 1.构建根证书前,需要构建随机数文件(.rand) ...
- vue-element-table-js去重合并单元格解析【实战需求】
有数据如下: { '2019-01-23': [ { 'channel': 'zp', 'listScanListNum': 24, 'listParseOkNum': 0, 'listPersonM ...
- linux shell 脚本攻略学习12--文件权限详解,chmod命令详解,chown命令详解,chattr命令详解
文件权限详解 一.chmod命令详解 文件权限和所有权是Unix/Linux文件系统最显著的特征之一.linux中的每一个文件都与多种权限类型相关联,在这些权限中主要分类为3种: 用户(User)是文 ...
- Codeforces Round #475 (Div. 2) C - Alternating Sum
等比数列求和一定要分类讨论!!!!!!!!!!!! #include<bits/stdc++.h> #define LL long long #define fi first #defin ...
- oracle数据库连接错误解决办法
ORA-28547 连接服务器失败,可能是Oracle Net 管理错误 原文地址:http://www.linuxidc.com/Linux/2014-11/109686.htm 上周去给客户培训O ...
- WEP/WPA-PSK密码破解工具aircrack-ng
WEP/WPA-PSK密码破解工具aircrack-ng aircrack-ng是Aircrack-ng工具集中的一个工具.该工具主要用于根据已经抓取的.cap文件或者.ivs文件破解出WEP/W ...
- Django模版语言inclusion_tag的用法。
inclusion_tag.它多用于一个HTML片段的.例如我写的一个BBS项目中. 一个博主的主页面的左侧栏和查看博主某篇文章的页面的左栅栏的一样的.为了不用重复写同样的代码.且提高页面的扩 ...
- NOIP练习赛题目5
小象涂色 难度级别:C: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 小象喜欢为箱子涂色.小象现在有c种颜色,编号为0~c-1:还有n个箱 ...
- javaSrript_数据类型(2017-03-15)
一.综述 javaScript中的数据类型分为两类: 基本类型: undefined:未定义.当声明变量却没有赋值时会显示该值.可以为变量赋值为undefined null:空.无.表示不存在,当为对 ...