安卓开发_浅谈Android动画(二)
在学习了四个基本动画之后,现在要学习一些更有用的效果
先给出所有的动画xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha
android:duration=""
android:fromAlpha="0.1"
android:toAlpha="1.0" >
</alpha> </set>
alpha.xml 透明动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <rotate
android:duration=""
android:fromDegrees=""
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="+360" /> </set>
rotate.xml旋转动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <scale
android:duration=""
android:fillAfter="false"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" /> </set>
scale.xml缩放动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <translate
android:duration=""
android:fromXDelta=""
android:fromYDelta=""
android:toXDelta=""
android:toYDelta="" /> </set>
translate.xml位移动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" > <scale
android:duration=""
android:fromXScale="0.1"
android:fromYScale="0.1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
<alpha
android:duration=""
android:fromAlpha=""
android:toAlpha="1.0" />
</set>
zoom_in.xml //activty进入动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top" > <scale
android:duration="@android:integer/config_mediumAnimTime"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="0.1"
android:toYScale="0.1" /> <alpha
android:duration="@android:integer/config_mediumAnimTime"
android:fromAlpha="1.0"
android:toAlpha="" /> </set>
zoom_out.xml//activity退出动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha
android:duration=""
android:fromAlpha="0.2"
android:toAlpha="1.0" />
<alpha
android:duration=""
android:fromAlpha="1.0"
android:startOffset=""
android:toAlpha="0.2" /> </set>
continue_anim.xml //连续动画
1、连续动画(动画监听器实现)
Animation loadAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);//先旋转
donghua_image.startAnimation(loadAnimation);
final Animation loadAnimation_2 = AnimationUtils.loadAnimation(this, R.anim.scale);//后缩放 //动画监听器
loadAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub }
//结束后的操作
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
donghua_image.startAnimation(loadAnimation_2);
}
});
效果图:

2、连续动画(配置文件实现)
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.continue_anim);
donghua_image.startAnimation(loadAnimation);
对应的配置文件
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha //先20%透明到100%透明,持续三秒
android:duration=""
android:fromAlpha="0.2"
android:toAlpha="1.0" />
<alpha //后100%透明到20%透明,持续三秒,从3秒后开始实现,即第一个动画实现完成后再实现
android:duration=""
android:fromAlpha="1.0"
android:startOffset=""
android:toAlpha="0.2" /> </set>
效果图:

3、闪烁动画效果
//循环播放透明度动画实现闪烁效果
//JAVA代码实现
AlphaAnimation alpha = new AlphaAnimation(0.1f, 1.0f);
alpha.setDuration();//每次0.1秒内执行完动画
alpha.setRepeatCount(); //执行10次动画
//重复方式。倒序Animation.REVERSE,正序Animation.START
alpha.setRepeatMode(Animation.REVERSE);
donghua_image.startAnimation(alpha);
效果图:

4、activity切换动画
使用overridePendingTransition方法
参数:第二个activity进入动画
第一个activity退出动画
在startActivity(intent);之后使用
效果图:

完整代码:
package other; import com.example.allcode.ImageTest;
import com.example.allcode.R; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView; public class Donghua extends Activity implements OnClickListener{
private Button toumingdu;
private Button suofang;
private Button weiyi;
private Button xuanzhuan;
private Button lianxu_1;
private Button lianxu_2;
private Button shanshuo; private ImageView donghua_image;
private Animation loadAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.donghua); toumingdu = (Button) findViewById(R.id.donghua_touming);
suofang = (Button) findViewById(R.id.donghua_suofang);
weiyi= (Button) findViewById(R.id.donghua_weiyi);
xuanzhuan= (Button) findViewById(R.id.donghua_xuanzhuan);
lianxu_1= (Button) findViewById(R.id.donghua_lianxu_1);
lianxu_2= (Button) findViewById(R.id.donghua_lianxu_2);
shanshuo= (Button) findViewById(R.id.donghua_shanshuo); donghua_image = (ImageView) findViewById(R.id.donghua_image);
toumingdu.setOnClickListener(this);
donghua_image.setOnClickListener(this);
suofang.setOnClickListener(this);
weiyi.setOnClickListener(this);
xuanzhuan.setOnClickListener(this);
lianxu_1.setOnClickListener(this);
lianxu_2.setOnClickListener(this);
shanshuo.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.donghua_touming:
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha);
donghua_image.startAnimation(loadAnimation);
break;
case R.id.donghua_suofang:
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.scale);
donghua_image.startAnimation(loadAnimation);
break;
case R.id.donghua_weiyi:
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.translate);
donghua_image.startAnimation(loadAnimation);
break;
case R.id.donghua_xuanzhuan:
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
donghua_image.startAnimation(loadAnimation);
break;
case R.id.donghua_lianxu_1:
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
donghua_image.startAnimation(loadAnimation);
final Animation loadAnimation_2 = AnimationUtils.loadAnimation(this, R.anim.scale); //动画监听器
loadAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub }
//结束后的操作
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
donghua_image.startAnimation(loadAnimation_2);
}
});
break;
case R.id.donghua_lianxu_2:
loadAnimation = AnimationUtils.loadAnimation(this, R.anim.continue_anim);
donghua_image.startAnimation(loadAnimation);
break;
case R.id.donghua_shanshuo:
//循环播放透明度动画实现闪烁效果
//JAVA代码实现
AlphaAnimation alpha = new AlphaAnimation(0.1f, 1.0f);
alpha.setDuration();//每次0.1秒内执行完动画
alpha.setRepeatCount(); //执行10次动画
//重复方式。倒序Animation.REVERSE,正序Animation.START
alpha.setRepeatMode(Animation.REVERSE);
donghua_image.startAnimation(alpha);
break;
default:
break;
}
} }
Donghua.java
<?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" > <Button
android:id="@+id/donghua_touming"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AlphaAnimation(透明度动画)" /> <Button
android:id="@+id/donghua_suofang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ScaleAnimation(缩放动画)" /> <Button
android:id="@+id/donghua_weiyi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TranslateAnimation(位移动画)" /> <Button
android:id="@+id/donghua_xuanzhuan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RotateAnimation(旋转动画)" /> <Button
android:id="@+id/donghua_lianxu_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="连续动画一(动画监听器实现)" />
<Button
android:id="@+id/donghua_lianxu_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="连续动画二(配置文件实现)" />
<Button
android:id="@+id/donghua_shanshuo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="闪烁动画" /> <ImageView
android:id="@+id/donghua_image"
android:layout_width="82dp"
android:layout_height="wrap_content"
android:layout_weight="0.16"
android:src="@drawable/icon_72" /> </LinearLayout>
donghua.xml
安卓开发_浅谈Android动画(二)的更多相关文章
- 安卓开发_浅谈Android动画(四)
Property动画 概念:属性动画,即通过改变对象属性的动画. 特点:属性动画真正改变了一个UI控件,包括其事件触发焦点的位置 一.重要的动画类及属性值: 1. ValueAnimator 基本属 ...
- 安卓开发_浅谈Android动画(三)
一.LayoutAnimation布局动画 用于为一个layout里面的控件,或者是一个ViewGroup里面的控件设置动画效果 在res-anim文件下新建一个动画xml文件 <?xml ve ...
- 安卓开发_浅谈Android动画(一)
动画效果,针对图片实现 现在学习四种基本的简单动画效果 一.Tween Animation共同属性 1.Duration:动画持续时间(毫秒单位) 2.fillAfter:设置为true,动画转化在动 ...
- 安卓开发_浅谈ListView(SimpleAdapter数组适配器)
安卓开发_浅谈ListView(ArrayAdapter数组适配器) 学习使用ListView组件和SimapleAdapter适配器实现一个带图标的ListView列表 总共3部分 一.MainAc ...
- 安卓开发_浅谈ListView(自定义适配器)
ListView作为一个实际开发中使用率非常高的视图,一般的系统自带的适配器都无法满足开发中的需求,这时候就需要开发人员来自定义适配器使得ListView能够有一个不错的显示效果 有这样一个Demo ...
- 安卓开发_浅谈Fragment之ListFragment
ListFragment,即Fragment的一个子类,当我们用的一个Fragment只需要一个listview视图的时候使用 该类有几个特点: 1.ListFragment 本身具只有一个ListV ...
- 安卓开发_浅谈OptionsMenus(选项菜单)
Android平台下所提供的菜单大体上可分为三类:选项菜单.上下文菜单和子菜单. 当Activity在前台运行时,如果用户按下手机上的Menu键,此时就会在屏幕低端弹出相应的选项菜单.但这个功能需要开 ...
- 安卓开发_浅谈AsyncTask
现在就来学习一下AsyncTask. 一.先介绍一下AsyncTask: 在开发Android移动客户端的时候往往要使用多线程来进行操作,我们通常会将耗时的操作放在单独的线程执行,避免其占用主线程而给 ...
- 安卓开发_浅谈ListView(ArrayAdapter数组适配器)
列表视图(ListView)以垂直的形式列出需要显示的列表项. 实现过程:新建适配器->添加数据源到适配器->视图加载适配器 在安卓中,有两种方法可以在屏幕中添加列表视图 1.直接用Lis ...
随机推荐
- 【转载】linux tail命令的使用方法详解
本文介绍Linux下tail命令的使用方法.linux tail命令用途是依照要求将指定的文件的最后部分输出到标准设备,通常是终端,通俗讲来,就是把某个档案文件的最后几行显示到终端上,假设该档案有更新 ...
- 二叉平衡查找树AvlTree(C实现)
二叉平衡查找树即是一棵树中所有节点的左右子树高度差不超过1的查找树 头文件—————————————————————————————— #ifndef _AVLTREE_H_ #define _AVL ...
- NopCommerce插件学习
在园子里看到这篇文章:http://www.cnblogs.com/haoxinyue/archive/2013/06/06/3105541.html写的非常好,我也是在此文章的基础上来一步步的学习N ...
- ADO.NET基础01
数据库中数据的导入导出 在使用一些数据库时,很多时候都要将文件导入导出到指定的文件夹中: 数据的导入导出就必须用到stream函数,这就必须用到Using System.IO的命名空间: **在数 ...
- 数论 - 算数基本定理的运用 --- nefu 118 : n!后面有多少个0
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php Mean: 略. analyse: 刚开始想了半天都没想出来,数据这么大,难道是有什么 ...
- 在ASP.NET MVC环境中使用加密与解密
在.NET Framework 4.5的NET框架中,在程序中加密与解密很方便.现在均学习ASP.NET MVC程序了,因此Insus.NET也在此写个学习的例子.在需要时可以参考与查阅. 写一个Ut ...
- Python入门笔记(14):Python的字符编码
一.字符编码中ASCII.Unicode和UTF-8的区别 点击阅读:http://www.cnblogs.com/kingstarspe/p/ASCII.html 再推荐一篇相关博文:http:// ...
- VS2013 编译程序时提示 无法查找或打开 PDB 文件
"Draw.exe"(Win32): 已加载"C:\Users\YC\Documents\Visual Studio 2013\Projects\Draw\Debug\ ...
- C#的Raw Socket实现网络封包监视
同Winsock1相比,Winsock2最明显的就是支持了Raw Socket套接字类型,使用Raw Socket,可把网卡设置成混杂模式,在这种模式下,我们可以收到网络上的IP包,当然包括目的不是本 ...
- C#为工作Sql而产生的字符串分割小工具(很实用,你值得拥有)
写在前面 为什么要写这个工具? 工作需要,拼接字符串头晕眼花拼接的,特别是in 查询,后面的参数太多,想在数据执行一些这个sql语句老费劲了. 看正文 工作所有的(后台)攻城狮们都会接触到sql语句, ...