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设置图片变化的四种效果代码的更多相关文章

  1. Android开发_Android数据的四种存储方式

    Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File.由于Android系统中,数据基本都是私有的的,都是存放 ...

  2. Android异步更新UI的四种方式

    Android异步更新UI的四种方式 2015-09-06 09:23 segmentfault 字号:T | T 大家都知道由于性能要求,android要求只能在UI线程中更新UI,要想在其他线程中 ...

  3. 转--Android按钮单击事件的四种常用写法总结

    这篇文章主要介绍了Android按钮单击事件的四种常用写法总结,比较了常见的四种写法的优劣,有不错的参考借鉴价值,需要的朋友可以参考下     很多学习Android程序设计的人都会发现每个人对代码的 ...

  4. 详解Android开发中Activity的四种launchMode

    Activity栈主要用于管理Activity的切换.当使用Intent跳转至某个目标Activity,需要根据目标Activity的加载模式来加载. Activity一共有以下四种launchMod ...

  5. android点击事件的四种方式

    android点击事件的四种方式 第一种方式:创建内部类实现点击事件 代码如下: package com.example.dail; import android.text.TextUtils; im ...

  6. Android按钮单击事件的四种常用写法

    这篇文章主要介绍了Android按钮单击事件的四种常用写法总结,比较了常见的四种写法的优劣,有不错的参考借鉴价值,需要的朋友可以参考下 很多学习Android程序设计的人都会发现每个人对代码的写法都有 ...

  7. Android(java)学习笔记106:Android设置文本颜色的4种方法

    1. Android设置文本颜色的4种方法: (1)利用系统自带的颜色类: tv.setTextColor(android.graphics.Color.RED); (2)数字颜色表示: tv.set ...

  8. Android中点击事件的四种写法详解

    Android中点击事件的四种写法 使用内部类实现点击事件 使用匿名内部类实现点击事件 让MainActivity实现View.OnClickListener接口 通过布局文件中控件的属性 第一种方法 ...

  9. Android跨进程通信的四种方式

    由于android系统中应用程序之间不能共享内存.因此,在不同应用程序之间交互数据(跨进程通讯)就稍微麻烦一些.在android SDK中提供了4种用于跨进程通讯的方式.这4种方式正好对应于andro ...

随机推荐

  1. mysql-cluster集群原理介绍和搭建步骤(四个data/sql节点) (转)

    MySQL簇概述 MySQL簇是一种技术,该技术允许在无共享的系统中部署“内存中”数据库的簇.通过无共享体系结构,系统能够使用廉价的硬件,而且对软硬件无特殊要求.此外,由于每个组件有自己的内存和磁盘, ...

  2. [Leetcode] implement strStr() (C++)

    Github leetcode 我的解题仓库   https://github.com/interviewcoder/leetcode 题目: Implement strStr(). Returns ...

  3. 对话框(alert,prompt,confirm,showModalDialog)

    alert大部分浏览器中会产生阻塞,confirm,prompt都会产生阻塞 关于showModalDialog的介绍:(转自JS中showModalDialog 详细使用) 基本介绍:        ...

  4. js借用和绑定

    var one = { name:"object", say:function(greet) { return greet + ","+this.name; } ...

  5. 视差滚动(Parallax Scrolling)效果的原理与实现

    视差滚动(Parallax Scrolling)效果的原理与实现1.视差滚动效果的主要特点:    1)直观的设计,快速的响应速度,更合适运用于单页面    2)差异滚动 分层视差    页面上很多的 ...

  6. document.cookie

    概念相关: cookie是存于用户硬盘上的一个文件,对应一个域名,当浏览器再次访问这个域名时,便使用这个cookie. cookie 可以跨越一个域名下的多个网页,但不能跨越多个域名使用. cooki ...

  7. [Mugeda HTML5技术教程之15]案例分析:制作移动教育课件

    本文档要分析的案例是一个一氧化碳还原氧化铜的教育小课件,从中可以体会一些Mugeda API的用法和使用Mugeda动画制作移动教育课件的方法.Mugeda为移动教育领域和移动数字出版领域提供理想的教 ...

  8. [POJ] 2352 Stars [线段树区间求和]

    Stars Description Astronomers often examine star maps where stars are represented by points on a pla ...

  9. nginx日志管理与限速

    1.日志简介nginx日志主要有两种:访问日志和错误日志.访问日志主要记录客户端访问nginx的每一个请求,格式可以自定义:错误日志主要记录客户端访问nginx出错时的日志,格式不支持自定义.两种日志 ...

  10. 利用sql命令把结果集输出到文件

    利用sql命令把结果集输出到文件 红色部分的三条命令完成把结果集输出到文件!! [root@test root]# psql -hlocalhost -Utest testWelcome to psq ...