android xml实现animation 4种动画效果
animation有四种动画类型 分别为alpha(透明的渐变)、rotate(旋转)、scale(尺寸伸缩)、translate(移动),二实现的分发有两种,一种是javaCode,另外一种是XML,而我今天要说的是XML实现的方法,个人感觉javaCode的实现方法比xml要简单,所以有需要的可以自己去找找资料看看。下面是我的四个xml文件,分别代表这四种动画类型。
alpha.xml
COde:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<!-- 渐变透明的动画效果 -->
<!--fromAlpha 动画起始透明的 1.0完全不透明
toAlpha 动画结束时透明的 0.0完全透明
startOffset 设置启动时间
duration 属性动画持续时间
-->
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="500"
android:duration="5000"
/>
</set>
rotate.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<!-- 画面转移旋转动画效果 -->
<!--
fromDegrees开始角度
toDegrees结束角度
pivotX设置旋转时的X轴坐标
-->
<rotate
android:fromDegrees="0"
android:toDegrees="+360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000"
/>
</set>
scale.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<!-- 渐变尺寸伸缩动画效果 -->
<!--
fromXScale 起始x轴坐标
toXScale 止x轴坐标
fromYScale 起始y轴坐标
toYScale 止y轴坐标
pivotX 设置旋转时的X轴坐标
pivotY 设置旋转时的Y轴坐标
duration 持续时间
-->
<scale
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000"
/>
</set>
translate.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<!-- 画面转移位置移动动画效果 -->
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="5000"
/>
</set>
下面是主界面xml的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="200px"
/>
<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="200px"
/>
<ImageView
android:id="@+id/image3"
android:layout_width="match_parent"
android:layout_height="200px"
/>
<ImageView
android:id="@+id/image4"
android:layout_width="match_parent"
android:layout_height="200px"
/>
</LinearLayout>
然后是Activity代码
public class AnimationDemo extends Activity{
private Animation animation,animation1,animation2,animation3;
private ImageView image1,image2,image3,image4;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.animation);
initView();
}
public void initView()
{
animation=AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.rotate);
animation1=AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.scale);
animation2=AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.alpha);
animation3=AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.translate);
image1=(ImageView)findViewById(R.id.image1);
image1.setImageResource(R.drawable.jpeg);
image2=(ImageView)findViewById(R.id.image2);
image2.setImageResource(R.drawable.jpg);
image3=(ImageView)findViewById(R.id.image3);
image3.setImageResource(R.drawable.png);
image4=(ImageView)findViewById(R.id.image4);
image4.setImageResource(R.drawable.gif);
image1.startAnimation(animation);
image2.startAnimation(animation1);
image3.startAnimation(animation2);
image4.startAnimation(animation3);
}
}
好了,就这样就是先了四种动画效果,另外还有一个知识点,是动画里面的速率问题,有需要的可以去上网百度看看吧。
实现效果如下:
android xml实现animation 4种动画效果的更多相关文章
- android动画介绍--Animation 实现loading动画效果
Animation的使用方法并不难.这里简单的介绍一下使用方法. 先看效果图: 效果还是不错的吧. 下面来看看使用方法. 动画效果是通过Animation来实现的,一共有四种,分别为: AlphaAn ...
- UI特效--Android利用ViewFlipper实现屏幕切换动画效果
.屏幕切换指的是在同一个Activity内屏幕见的切换,最长见的情况就是在一个FrameLayout内有多个页面,比如一个系统设置页面:一个个性化设置页面.2.介绍ViewFilpper类ViewFl ...
- Mono For Android中简单实现按钮的动画效果
Android中动画的分Tween Animation和Frame Animation,本节主要讲Tween Animation的实现. 一般是通过XML文件来定义动画的,具体如下: 1.在项目res ...
- Android利用ViewFlipper实现屏幕切换动画效果
1.屏幕切换指的是在同一个Activity内屏幕见的切换,最长见的情况就是在一个FrameLayout内有多个页面,比如一个系统设置页面:一个个性化设置页面. 2.介绍ViewFilpper类 Vie ...
- 一起学android之设置ListView数据显示的动画效果(24)
效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFpX3FpbmdfeHVfa29uZw==/font/5a6L5L2T/fontsize/40 ...
- css3,transition,animation两种动画实现区别
我们为页面设置动画时,往往会用到transition还有animation以及transfrom属性或者用到js. 其实通常情况下,对于使用js我们更加倾向于使用css来设置动画. transfrom ...
- Core Animation之多种动画效果
前面介绍了Core Animation基础知识,还有CALayer的简单使用,最终还是有要动画的滴,这里列出几个动画效果,参考下能加深对Core Animation的认识和理解 1.把图片移到右下角变 ...
- Android开发Activity全局切换的动画效果
切换动画 slide_left_in.xml 从左边进 --> 退出的时候使用 <?xml version="1.0" encoding="utf-8&quo ...
- 关于Android WindowManager显示悬浮窗的动画效果
要实现WindowManager添加的窗口,实现动画显示,就需要添加如下红色的属性,其他的添加View只要设置其Animations属性也会实现动画,当然自己实现也可,但是能直接用系统的已经实现好的, ...
随机推荐
- drupal对数据库操作
// nodenode_load($nid = NULL, $vid = NULL, $reset = FALSE);node_load_multiple($nids = array(), $cond ...
- 04_Spring中使用Quartz
[Spring中使用SimplerTrigger] [QuartzTask.java] package com.higgin.task; import java.text.SimpleDateForm ...
- SharePoint 2013 - Bootstrap
1. 在SharePoint 2013中应用Bootstrap时,需要添加以下css: <style> .container{ margin-left:0px; //为了使containe ...
- 解决Android报错No resource found that matches the given name (at 'text' with value '@string/hello').
解决Android项目No resource found that matches the given name (at 'text' with value '@string/hello'). 如图, ...
- 自整定模糊PID算法的理论
模糊控制系统的构成与与常规的反馈控制系统的主要区别在于控制器主要是由模糊化,模糊推理机和精确化三个功能模块和知识库(包括数据库和规则库)构成的.具体实现过程如下所示: (1)预处理: 输入数据往往是通 ...
- matlab练习程序(演化策略ES)
还是这本书上的内容,不过我看演化计算这一章是倒着看的,这里练习的算法正好和书中介绍的顺序是相反的. 演化策略是最古老的的演化算法之一,和上一篇DE算法类似,都是基于种群的随机演化产生最优解的算法. 算 ...
- Redis安装及配置
Redis缓存数据库 借鉴出处 http://www.runoob.com/redis/redis-install.html http://www.runoob.com/redis/redis-con ...
- #单元测试#以karma+mocha+chai 为测试框架的Vue webpack项目(一)
目标: 为已有的vue项目搭建 karma+mocha+chai 测试框架 编写组件测试脚本 测试运行通过 抽出共通 一.初始化项目 新建项目文件夹并克隆要测试的已有项目 webAdmin-web 转 ...
- python入门21 pip安装、更新、卸载第三方包,验证包是否安装成功;pip自身更新升级
1 安装第三方包 python3自带安装工具pip,且在安装时勾选添加path也会将pip.exe所在目录加入到环境变量(python安装目录\Scripts). 因此安装第三方软件特别简单,打开命令 ...
- VMware,win7与linux centos6.4文件互传,linux下挂载windows共享文件夹,vmware tools安装方法
本方法是以win7,VMware9.0.1 ,centos6.4为基础实验的. 对于linux的初级使用阶段,都会Windows中使用linux虚拟机VMWare或者其它的.在Windows与linu ...