Android学习笔记-tween动画之java实现
Android动画分为Tween动画和Frame动画,近期学习了,体tween动画,现在讲学习的心得以及相关知识介绍如下。
Tween又称为补间动画,可以把对象进行缩小、放大、旋转和渐变等操作。
//设置播放时间
animation.setDuration(2000); //设置重复的次数,记着是重复的次数 animation.setRepeatCount(2); //设置重复的模式,有两种RESTART:重新开始与REVERSE:反向开始 animation.setRepeatMode(AlphaAnimation.REVERSE); //启动播放 iv.startAnimation(animation);
第三:实例,
布局文件我们这样写,
<LinearLayout 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" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.ftf.tween.MainActivity" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:onClick="click" android:text="透明度" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" /> <Button android:onClick="click2" android:text="缩放" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" /> <Button android:onClick="click3" android:text="旋转" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" /> <Button android:onClick="click4" android:text="平移" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" /> <Button android:onClick="click5" android:text="组合" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <ImageView android:id="@+id/iv" android:src="@drawable/ic_launcher" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
// 透明度变化
public void click(View view) { AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(2000); animation.setRepeatCount(2); animation.setRepeatMode(AlphaAnimation.REVERSE); iv.startAnimation(animation); } public void click2(View view) { ScaleAnimation animation = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(2000); animation.setRepeatCount(2); animation.setRepeatMode(AlphaAnimation.REVERSE); iv.startAnimation(animation); } public void click3(View view) { RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(2000); animation.setRepeatCount(2); animation.setRepeatMode(AlphaAnimation.REVERSE); iv.startAnimation(animation); } public void click4(View view) { TranslateAnimation animation = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, 0.2f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.2f, Animation.RELATIVE_TO_PARENT, 1.0f); animation.setDuration(2000); animation.setRepeatCount(2); animation.setRepeatMode(AlphaAnimation.REVERSE); iv.startAnimation(animation); } public void click5(View view) { //设置混合模式,也即多重播放效果放在一起。 AnimationSet set = new AnimationSet(false); TranslateAnimation pa = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, 0.2f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.2f, Animation.RELATIVE_TO_PARENT, 1.0f); pa.setDuration(2000); pa.setRepeatCount(2); pa.setRepeatMode(AlphaAnimation.REVERSE); RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); ra.setDuration(2000); ra.setRepeatCount(2); ra.setRepeatMode(AlphaAnimation.REVERSE); ScaleAnimation sa = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); sa.setDuration(2000); sa.setRepeatCount(2); sa.setRepeatMode(AlphaAnimation.REVERSE); set.addAnimation(sa); set.addAnimation(ra); set.addAnimation(pa); iv.startAnimation(set); }
Android学习笔记-tween动画之java实现的更多相关文章
- Android学习笔记-tween动画之xml实现
继上篇tween动画的java实现:http://www.cnblogs.com/fengtengfei/p/3957800.html, 这里我接着介绍一下tween动画的xml实现的方法, 首先 ...
- Android学习笔记_55_Tween动画 (渐变、缩放、位移、旋转)
Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变).第二类就是 Frame动画,即顺序的播放事先做好的图像,与gi ...
- Android学习笔记_39_tween动画的实现(Animation和Frame)
一.Animation动画的实现及特点: 1.Tween动画,通过对 View 的内容进行一系列的图形变换 (包括平移.缩放.旋转.改变透明度)来实现动画效果. 动画效果的定义可以采用XML来做也 ...
- Android学习笔记02-Mac下编译java代码
在Mac OS上配置JDK 1.7. 一 下载 Mac版本的JDK1.7 从以下下载地址,下载Mac版本的JDk1.7 安装文件 jdk-7u79-macosx-x64.dmg. http://www ...
- Android学习笔记01-Mac下搭建Java开发环境
一 安装JDK 下载 mac 下专用的jdk1.7, 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downlo ...
- Android学习笔记(四) JAVA基础知识回顾
一.接口 1)接口中定义的方法都是public权限,并且默认为public,而不是default. 2)接口的实现(implements)是特殊的继承,类似于父类子类的关系,可以向上转型(非常重要). ...
- Android 学习笔记之Volley(七)实现Json数据加载和解析...
学习内容: 1.使用Volley实现异步加载Json数据... Volley的第二大请求就是通过发送请求异步实现Json数据信息的加载,加载Json数据有两种方式,一种是通过获取Json对象,然后 ...
- Android学习笔记进阶之在图片上涂鸦(能清屏)
Android学习笔记进阶之在图片上涂鸦(能清屏) 2013-11-19 10:52 117人阅读 评论(0) 收藏 举报 HandWritingActivity.java package xiaos ...
- Android学习笔记之JSON数据解析
转载:Android学习笔记44:JSON数据解析 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,为Web应用开发提供了一种 ...
随机推荐
- 零基础入门学习Python(31)--永久存储:腌制一缸美味的泡菜
知识点 pickle( 泡菜 ) 模块介绍: pickle模块作用是持久化的储存数据. 在Python程序运行中得到了一些字符串.列表.字典等数据,想要长久的保存下来,方便以后使用, 而不是简单的放入 ...
- 23Spring使用JdbcTemplate和JdbcDaoSupport
首先需要添加c3p0包和jdbc包 数据库: CREATE DATABASE IF NOT EXISTS `spring` /*!40100 DEFAULT CHARACTER SET utf8 */ ...
- 【C++】使用find函数快速定位元素
当有了STL,你还在用遍历的土方法定位元素吗? 今天就来介绍一下,如何使用algorithm库里的find函数快速定位数组或向量中的元素. 首先当然要包含头文件: #include <algor ...
- Linux 网卡配置
网卡配置(环境CentOS 6.7) 图形界面修改: # 在命令行直接输入setup进入配置 1.[root@mingyaun ~]# setup 2.NetWork configuration 3. ...
- 笔记——python语言规范
Lint 对你的代码运行pylint 定义: pylint是一个在Python源代码中查找bug的工具. 对于C和C++这样的不那么动态的(译者注: 原文是less dynamic)语言, 这些bug ...
- bzoj1007 [HNOI2008]水平可见直线 - 几何 - hzwer.com
Description Input 第一行为N(0 < N < 50000),接下来的N行输入Ai,Bi Output 从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必 ...
- Spring实战读书笔记
Spring实战读书笔记 Spring-core Spring之旅 - DI 和 AOP 概念 spring 的Bean容器 spring 的 核心模块 Spring的核心策略 POJO 最小侵入式编 ...
- [bzoj1059][ZJOI2007]矩阵游戏_二分图最大匹配
矩阵游戏 bzoj-1059 ZJOI-2007 题目大意:给定一个n*n的棋盘,上面有一些格子被染黑,剩下都是白色.你每次可以交换两列或者两行,问你能否通过一系列操作使得棋盘的主对角线上的格子全是黑 ...
- hdu4696 Answers(循环节+找规律)
题意: 分析: 容易想到先把T数组按位置和对应权值建一个有向图(类似置换群那种指法) 然后图建完了,如果C[]里面都是2,那显然只能凑出那些偶数,奇数是不能凑出来的 如果C[]有1有2呢? 事实上是可 ...
- Use Elasticksearch to solve TOP N issue
The raw data is like timestamp, router, interface, src_ip, dst_ip, protocol, pkts 10000000, 1.1.1.1 ...