android设置图片变化的四种效果代码
activity代码如下:
package com.example.chapter12_graphic_animation;
import android.os.Bundle;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
private Button b1,b2,b3,b4;
private ImageView girlImage;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.test);
this.getWindow().setBackgroundDrawable(drawable);
setContentView(R.layout.main);
girlImage=(ImageView)findViewById(R.id.ImageView01);
b1=(Button)findViewById(R.id.Button01);
b2=(Button)findViewById(R.id.Button02);
b3=(Button)findViewById(R.id.Button03);
b4=(Button)findViewById(R.id.Button04);
b1.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
//创建Scale尺寸变化动画
Animation scaleAnimation =new ScaleAnimation(0f,1f,0f,1f,
Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f);
//设置动画持续的时常
scaleAnimation.setDuration(3000);
//开始动画
girlImage.startAnimation(scaleAnimation);
}
});
b2.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
//创建Scale尺寸变化动画
Animation alphaAnimation =new AlphaAnimation(0.1f,1.0f);
//设置动画持续的时常
alphaAnimation.setDuration(3000);
//开始动画
girlImage.startAnimation(alphaAnimation);
}
});
b3.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
//创建Scale尺寸变化动画
Animation translateAnimation =new TranslateAnimation(10,100,10,100);
//设置动画持续的时常
translateAnimation.setDuration(3000);
//开始动画
girlImage.startAnimation(translateAnimation);
}
});
b4.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
//创建Scale尺寸变化动画
Animation rotateAnimation =new RotateAnimation(0f,+360f,
Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f);
//设置动画持续的时常
rotateAnimation.setDuration(3000);
//开始动画
girlImage.startAnimation(rotateAnimation);
}
});
}
//为按钮添加监听事件
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
XML代码设置如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Scale.." />
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Alpha..." />
<Button
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Translate..." />
<Button
android:id="@+id/Button04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Rotate..." />
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="@drawable/girl" />
</LinearLayout>
android设置图片变化的四种效果代码的更多相关文章
- Android开发_Android数据的四种存储方式
Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File.由于Android系统中,数据基本都是私有的的,都是存放 ...
- Android异步更新UI的四种方式
Android异步更新UI的四种方式 2015-09-06 09:23 segmentfault 字号:T | T 大家都知道由于性能要求,android要求只能在UI线程中更新UI,要想在其他线程中 ...
- 转--Android按钮单击事件的四种常用写法总结
这篇文章主要介绍了Android按钮单击事件的四种常用写法总结,比较了常见的四种写法的优劣,有不错的参考借鉴价值,需要的朋友可以参考下 很多学习Android程序设计的人都会发现每个人对代码的 ...
- 详解Android开发中Activity的四种launchMode
Activity栈主要用于管理Activity的切换.当使用Intent跳转至某个目标Activity,需要根据目标Activity的加载模式来加载. Activity一共有以下四种launchMod ...
- android点击事件的四种方式
android点击事件的四种方式 第一种方式:创建内部类实现点击事件 代码如下: package com.example.dail; import android.text.TextUtils; im ...
- Android按钮单击事件的四种常用写法
这篇文章主要介绍了Android按钮单击事件的四种常用写法总结,比较了常见的四种写法的优劣,有不错的参考借鉴价值,需要的朋友可以参考下 很多学习Android程序设计的人都会发现每个人对代码的写法都有 ...
- Android(java)学习笔记106:Android设置文本颜色的4种方法
1. Android设置文本颜色的4种方法: (1)利用系统自带的颜色类: tv.setTextColor(android.graphics.Color.RED); (2)数字颜色表示: tv.set ...
- Android中点击事件的四种写法详解
Android中点击事件的四种写法 使用内部类实现点击事件 使用匿名内部类实现点击事件 让MainActivity实现View.OnClickListener接口 通过布局文件中控件的属性 第一种方法 ...
- Android跨进程通信的四种方式
由于android系统中应用程序之间不能共享内存.因此,在不同应用程序之间交互数据(跨进程通讯)就稍微麻烦一些.在android SDK中提供了4种用于跨进程通讯的方式.这4种方式正好对应于andro ...
随机推荐
- Hadoop文件的基本操作
Hadoop提供了大量的API对文件系统中的文件进行操作,主要包括: (1)读取文件 (2)写文件 (3)读取文件属性 (4)列出文件 (5)删除文件 1、读取文件 以下示例中,将hdfs中的一个文件 ...
- xen之基本搭建
1. 前言 所需包: kernel-xen xen xen-libs (xen依赖包) xen_runtime (xen依赖包) 以上xen包需要版本号一致,例如4.1.3版本,这里使用xm接口管理工 ...
- 使用nRF51822/nRF51422创建一个简单的BLE应用 ---入门实例手册(中文)之五
5应用测试 需要一个USB dongle与开发板evaluation kit,并配合Master Control Panel软件,以用于测试BLE应用.前期的准备工作在<nRF51822 Eva ...
- Scala学习笔记--提取器unapply
提取器就是一个带有unapply方法的对象.你可以把unapply方法当做是伴生对象中apply方法的反向操作. apply方法接收构造参数,然后将他们变成对象. 而unapply方法接受一个对象,然 ...
- AsEnumrable和AsQueryable的区别
http://www.cnblogs.com/jianglan/archive/2011/08/11/2135023.html 在写LINQ语句的时候,往往会看到.AsEnumerable() 和 . ...
- 什么是dtd文件,为什么需要dtd
DTD为英文Document Type Definition,中文意思为"文档类定义".DTD肩负着两重任务:一方面它帮助你编写合法的代码,另一方面它让浏览器正确地显示器代码.也许 ...
- XJOI网上同步训练DAY1 T3
思路:一开始看到这题的时候想DP,可是发现貌似不行..因为有前缀也有后缀,而且有的后缀会覆盖到现在的前缀,这就不满足无后效性了啊! 但是有个很巧妙的思路:如果我们知道a[i]的最大值,那么p的数量和q ...
- DDP和DDU什么区别
DU/DDP 就是A发货给国外B,B只要呆在家里看电视,货会自动送上门,当中的所有运输清关等事情都是由A来负责(A可以委托货代来负责),区别就是DDU是不包括税金的,也就是货值的百分之多少,税金会在B ...
- JSP页面中文参数传递get和post方法分析
原文 http://developer.51cto.com/art/200907/133499.htm 在项目中,我们经常遇到需要在JSP页面切换中传递中文字符.这主要有两种方式. ◆URL方式 例如 ...
- android的原理--为什么我们不需要手动关闭程序
内容搜集自网络,有所删改 不用在意剩余内存的大小,其实很多人都是把使用其他系统的习惯带过来来了.android大多应用没有退出的设计其实是有道理的,这和系统对进程的调度机制有关系.如果你知 ...