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 ...
随机推荐
- shell中的if语句
语法格式 if command;then commands fi 其中的command包含如下: shell command 任何shell命令,如果shell命令返回0,代表true,否则,代表fa ...
- Lua 字符串 匹配模式 总结
字符类 %a --字母alpha %d --数字double %l --小写字母lower %u --大写字母upper %w --字母和数字word %x -- 十六进制 %z --代表0 zero ...
- 文件系统:介绍一个高大上的东西 - 零基础入门学习Python030
文件系统:介绍一个高大上的东西 让编程改变世界 Change the world by program 接下来我们会介绍跟Python的文件相关的一些十分有用的模块.模块是什么?不知大家对以下代码还有 ...
- DataTables选择行并删除(删除单行)
$(document).ready(function() { var table = $('#example').DataTable(); $('#example tbody').on( 'click ...
- 使用QtCreator作为ROS调试器
如果你用过QtCreator,你一定会喜欢上它. 流畅的速度,强大的功能,优雅的外观,友好的界面,一切让人如此舒服.而且它支持从命令行作为调试器启动,只需加上-debug exe即可. 因此我想如果能 ...
- poj3537--Crosses and Crosses
题意:有个一维棋盘,两人轮流下棋,然后谁连成三个谁赢 记得去年fj夏令营有见过这题,但是太弱了, 不会做. 记忆化搜索,如果n<=3肯定先手必胜,递推即可. #include<iostre ...
- AJAX实例入门
一.开门见山 这些时间,瞎子也看得见,AJAX正大踏步的朝我们走来.不管我们是拥护也好,反对也罢,还是视而不见,AJAX像一阵潮流,席转了我们所有的人. 关于AJAX的定义也好,大话也好,早有人在网上 ...
- 【转】ubuntu下解压缩zip,tar,tar.gz和tar.bz2文件
原文网址:http://blog.sina.com.cn/s/blog_5da93c8f0101h1uj.html 在Linux下面如何去压缩文件或者目录呢? 在这里我们将学习zip, tar, ta ...
- c++ 07
一.多重继承 1)子类同时拥有两个或两个以上的基类,同时继承了所有基类的属性和行为. 销售员 经理 \ / 销售经理 汽车 客用特性 商用特性 \ | / ...
- HashMap Java Doc
原文 public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneab ...