tweenanim动画
1、视图
<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"
tools:context=".MainActivity" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click1"
android:text="透明"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click2"
android:text="缩放"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click3"
android:text="旋转"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click4"
android:text="平移"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click5"
android:text="组合"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
</LinearLayout> </LinearLayout>
2、android代码
package com.example.tweenanim; import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView; public class MainActivity extends Activity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
} //透明度
public void click1(View view){
//第一个参数表示开始透明度;0表示完全透明
//第二个参数表示结束透明度;1表示完全不透明
AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(2000);//设置动画时间为2妙
animation.setRepeatCount(2);//设置重复次数,因此总共3次
animation.setRepeatMode(Animation.REVERSE);//设置重复模式
iv.startAnimation(animation);
} //缩放图片
public void click2(View view){
//第一个参数为开始x轴缩放坐标;第二个参数为结束时x轴缩放坐标
//第三个参数为开始y轴缩放坐标;第四个参数为结束时y轴缩放坐标
//第五个参数为中心x坐标以什么为参照,Animation.RELATIVE_TO_SELF说明以自己为参照;第六个参数为参照坐标比例;第七、八与第五、六相同,只不过它指的是y轴
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(Animation.REVERSE);
iv.startAnimation(animation);
} //旋转
public void click3(View view){
//第一参数,开始旋转角度
//第二个参数为旋转到多少度
//第3-6个参数与缩放的第5-8的参数相同
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(Animation.REVERSE);
iv.startAnimation(animation);
} //平移
public void click4(View view){
//x轴
//第一个参数为参照类型:Animation.RELATIVE_TO_PARENT以父窗口为参照
//第二个参数为开始坐标比例
//第三个同第一个;第四个参数是说明要平移多长的比例;1.0说明要有父窗口的宽度 //y轴同上 TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f);
animation.setDuration(2000);
animation.setRepeatCount(2);
animation.setRepeatMode(Animation.REVERSE);
iv.startAnimation(animation);
} //组合动画
public void click5(View view){
AnimationSet set = new AnimationSet(false); TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f);
ta.setDuration(2000);
ta.setRepeatCount(2);
ta.setRepeatMode(Animation.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(Animation.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(Animation.REVERSE); set.addAnimation(ta);
set.addAnimation(ra);
set.addAnimation(sa);
iv.startAnimation(set);
} }
tweenanim动画的更多相关文章
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变). 第二类就是 Frame动画,即顺序的播放事先做好的图像,与g ...
- Android(java)学习笔记199:Android中补间动画(Tween Animation)
本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画,可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1. ...
- Android 动画系列
Android种最常用的动画: ~1~Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变) Tweene Animations 主要类: Animation ...
- 以xml的方式实现动画
1.java代码 package com.example.tweenanim; import android.os.Bundle; import android.app.Activity; impor ...
- 【转】android动画之Tween动画 (渐变、缩放、位移、旋转)
原文:http://blog.csdn.net/feng88724/article/details/6318430 Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的 ...
- Android学习笔记_55_Tween动画 (渐变、缩放、位移、旋转)
Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变).第二类就是 Frame动画,即顺序的播放事先做好的图像,与gi ...
- Android(java)学习笔记142:Android中补间动画(Tween Animation)
本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画, 可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1 ...
- 动画requestAnimationFrame
前言 在研究canvas的2D pixi.js库的时候,其动画的刷新都用requestAnimationFrame替代了setTimeout 或 setInterval 但是jQuery中还是采用了s ...
- 梅须逊雪三分白,雪却输梅一段香——CSS动画与JavaScript动画
CSS动画并不是绝对比JavaScript动画性能更优越,开源动画库Velocity.js等就展现了强劲的性能. 一.两者的主要区别 先开门见山的说说两者之间的区别. 1)CSS动画: 基于CSS的动 ...
随机推荐
- DOC下编译和运行带有包的java类文件
前言: 带有包名的java类在DOC下编译可以成功,但是运行出错 错误: 找不到或无法加载主类 com.soanl.socket.MyServer D盘temp文件下有个Hello.java文件,包 ...
- lua协程并发下载简单测试
下载8个1m大小文件,测试五次分别耗时12.038s,10.316s,8.955s,11.275s,9.499s(lua代码实现如下) require "socket" --hos ...
- find the most comfortable road(并差集,找差值最小的权值)
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 【Linux操作系统分析】设备驱动处理流程
1 驱动程序,操作系统,文件系统和应用程序之间的关系 字符设备和块设备映射到操作系统中的文件系统,由文件系统向上提供给应用程序统一的接口用以访问设备. Linux把设备视为文件,称为设备文件,通过对设 ...
- :before :after
#p1:before{ content: "哈哈哈 "; color: red;}#p1:after{ content: "哈哈哈"; color: #452d ...
- HTML之表格与表单
一.表格(table/tr/td) <table></table>表格 --不设高度 width:宽度.可以用像素或百分比表示. 常用960像素. border:边框,常用值为 ...
- linux: telnet
问题: telnet: connect to address 192.168.1.103: Connection refused 总结:{ 1. 需要开启telnet服务, /etc/xinetd.d ...
- DLL运行时动态加加载的问题
1.error C2440: 'initializing' : cannot convert from 'int (__stdcall *)(void)' to 'void (__cdecl *)(c ...
- iOS显示PDF
使用UIWebView来显示 //locale file NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUT ...
- 入门前端之HTML
本文内容: HTML概念 HTML元素 HTML属性 HTML标题 HTML段落 HTML格式化 HTML样式 HTML 链接 HTML 图像 HTML 表格 HTML 列表 HTML 块 HTML ...