安卓开发_浅谈Android动画(一)
动画效果,针对图片实现
现在学习四种基本的简单动画效果
一、Tween Animation共同属性
1、Duration:动画持续时间(毫秒单位)
2、fillAfter:设置为true,动画转化在动画结束后被应用
3、fillBefore:设置为true,动画转化在动画开始前被应用
4、interpolator:动画插入器(加速,减速插入器)
5、repeatCount:动画重复次数
6、repateMode:顺序重复/倒序重复
7、startOffset:动画之间的时间间隔
二、Animation实现方式
1、配置文件(/res/anim)--alpha,scale,translate,rotatae
2、JAVA代码实现--AlphaAnimation,ScaleAnimation,TranslateAnimation,RotateAnimation
三、四种基本动画
1、AlphaAnimation(透明度动画)
(1)fromAlpha:动画起始时的透明度
(2)toAlpha:动画终止时的透明度
0.0表示完全透明 1.0表示完全不透明
2、ScaleAnimation(缩放动画)
(1)fromX,toX分别是起始和结束时x坐标上的伸缩尺寸
(2)fromY,toY分别是起始和结束时y坐标上的伸缩尺寸
(3)pivotX,pivotY分别为伸缩动画相对于x,y,坐标开始的位置
3、TranslateAnimation(位移动画)
(1)、fromXDelta,fromYDelta分别是起始时X,Y的坐标
(2)、toXDelta,toYDelta分别是结束时X,Y的坐标
4、RotateAnimation(旋转动画)
(1)、fromDegrees 起始的角度
(2)、toDegrees 终止的角度
(3)、pivoteX,pivoteY分别为旋转动画相对于x,y的坐标的开始位置
四、示例
配置文件实现方法
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.Animation;
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 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); donghua_image = (ImageView) findViewById(R.id.donghua_image);
toumingdu.setOnClickListener(this);
donghua_image.setOnClickListener(this);
suofang.setOnClickListener(this);
weiyi.setOnClickListener(this);
xuanzhuan.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;
default:
break;
}
} }
布局文件:
<?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(旋转动画)" /> <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>
配置文件:
目录。res-anim 自己新建
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha
android:duration=""
android:fromAlpha="0.1"//初始透明度10%
android:toAlpha="1.0" //结束透明度100%
>
</alpha> </set>
alpha.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" > <rotate
android:duration=""
android:fromDegrees=""
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="+360" /> </set>
rotate.xml旋转动画
效果图:
安卓开发_浅谈Android动画(一)的更多相关文章
- 安卓开发_浅谈Android动画(四)
Property动画 概念:属性动画,即通过改变对象属性的动画. 特点:属性动画真正改变了一个UI控件,包括其事件触发焦点的位置 一.重要的动画类及属性值: 1. ValueAnimator 基本属 ...
- 安卓开发_浅谈Android动画(三)
一.LayoutAnimation布局动画 用于为一个layout里面的控件,或者是一个ViewGroup里面的控件设置动画效果 在res-anim文件下新建一个动画xml文件 <?xml ve ...
- 安卓开发_浅谈Android动画(二)
在学习了四个基本动画之后,现在要学习一些更有用的效果 先给出所有的动画xml <?xml version="1.0" encoding="utf-8"?& ...
- 安卓开发_浅谈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键,此时就会在屏幕低端弹出相应的选项菜单.但这个功能需要开 ...
- 安卓开发_浅谈Notification(通知栏)
Notification通知栏是显示在手机状态的消息,代表一种全局效果的通知 快速创建一个Notification的步骤简单可以分为以下四步: 第一步:通过getSystemService()方法得到 ...
- 安卓开发_浅谈ListView之分页列表
前言: 在开发的过程中,有时候我们需要从网络解析一些数据,比如最近的一些新闻,我们需要把这些数据用ListView显示出来. 因为是解析一个网络数据源,这样将会一下子将所有的数据解析出来,当数据源数据 ...
随机推荐
- php经典面试题与答案(转先锋教程网)
php经典面试题与答案 时间:2016-02-29 16:06:23来源:网络 导读:php经典面试题与答案,包括腾讯php面试题.百度php面试题.新浪php面试题等 php面试题及答案 1,禁 ...
- 关于在for循环中绑定事件打印变量i是最后一次。
其实函数引用的外部变量都是最后一次的值. <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- ADT-bundle(Android Development Tools)环境配置
Android开发环境有两套比较主流的:ADT-bundle和Android Studio,前者是Eclipse插件的形式进行开发,后者是Android的官方IDE. ADT环境的配置与调试:(1)安 ...
- C#/C++ 中字节数组与int类型转换
1.C#中int和byte[]转换: /// <summary> /// 把int32类型的数据转存到4个字节的byte数组中 /// </summary> /// <p ...
- AC_Dream 1224 Robbers(贪心)
题意:n个抢劫犯分别抢到的金钱是k1, k2, k3,...,一共得到的金钱是m, 但是在分钱的时候是按照x1/y, x2/y, x3/y,....的比例进行分配的!这样的话 一些抢劫犯就会觉得不公平 ...
- 使用Html5+C#+微信 开发移动端游戏详细教程 :(五)游戏图像的加载与操作
当我们进入游戏时,是不可能看到所有的图像的,很多图像都是随着游戏功能的打开而出现, 比如只有我打开了"宝石"菜单才会显示宝石的图像,如果是需要显示的时候才加载, 会对用户体验大打折 ...
- iOS-图片轮播-SDCycleSCrollView的使用
介绍: SDCycleScrollView 是一款非常强大的轮播图第三方. 轮播流畅,手滑流畅.使用方便.自定义简单. 可以更改pageControl. 一. Demo地址 https://pan.b ...
- LeetCode-95. Unique Binary Search Trees II
Description: Given n, generate all structurally unique BST's (binary search trees) that store values ...
- CentOS6.5菜鸟之旅:关于搜索的shell命令
一.locate命令 用于模糊搜索文件(目录)的绝对路径. 示例1: // 凡是绝对路径当中含jdk字符串的文件(目录)均被搜索出来 fsjohnhuang@fsjohnhuang~# locate ...
- SQL 分类统计函数
SELECT TransactionNumber,SUM(CASE WHEN ReasonLevel=0 THEN TransactionNumber ELSE 0 end ) a ...