`

通过Scale的方式打开一个新的Activity

阅读更多
1. ScaleActivity.java文件
package cn.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ScaleActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		/* 以findViewById()取得Button对象,并添加onClickListener */
		Button b1 = (Button) findViewById(R.id.Button01);
		b1.setOnClickListener(new Button.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				/* new一个Intent对象,并指定class */
				Intent intent = new Intent();
				intent.setClass(ScaleActivity.this, Activitya.class);
				/* 调用Activity EX03_10_1 */
				startActivity(intent);
			}
		});
	}
}

2.ScaleAnimationHelper.java文件
package cn.com;

import android.content.Context;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;

public class ScaleAnimationHelper {
	Context con;

	int order;

	public ScaleAnimationHelper(Context con, int order) {
		this.con = con;
		this.order = order;
	}

	AlphaAnimation myAnimation_Alpha;
	ScaleAnimation myAnimation_Scale;

	public void ScaleOutAnimation(View view) {
		myAnimation_Alpha = new AlphaAnimation(1.0f, 0.1f);
		myAnimation_Scale = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1f,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		myAnimation_Scale.setInterpolator(new AccelerateInterpolator());

		AnimationSet aa = new AnimationSet(true);
		aa.addAnimation(myAnimation_Alpha);
		aa.addAnimation(myAnimation_Scale);
		aa.setDuration(1000);

		view.startAnimation(aa);
	}

	public void ScaleInAnimation(View view) {

		myAnimation_Scale = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		myAnimation_Scale.setDuration(1000);
		myAnimation_Scale.setInterpolator(new AccelerateInterpolator());

		AnimationSet aa = new AnimationSet(true);
		aa.addAnimation(myAnimation_Scale);
		// aa.setDuration(1000);

		view.startAnimation(aa);
	}
}

3. Activitya.java文件
package cn.com;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.view.View.OnClickListener;

public class Activitya extends Activity implements OnClickListener {
	ViewGroup v;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.newq);

		v = (LinearLayout) findViewById(R.id.news);

		Button Button01 = (Button) findViewById(R.id.Button01);

		Button01.setOnClickListener(this);

		// 显示layout进行缩放动画效果
		ScaleAnimationHelper scaleHelper = new ScaleAnimationHelper(this, 1);
		scaleHelper.ScaleOutAnimation(v);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		// 显示layout进行缩放动画效果
		//ScaleAnimationHelper scaleHelper = new ScaleAnimationHelper(this, 1);
		//scaleHelper.ScaleInAnimation(v);
	}
}

4.main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">

	<Button android:text="StartActivity" android:id="@+id/Button01"
		android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>


5.newq.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:background="#123456"
	android:layout_height="fill_parent" android:id="@+id/news"
	android:orientation="vertical">
	<TextView android:text="this is the second activity"
		android:id="@+id/TextView01" android:layout_width="wrap_content"
		android:layout_height="wrap_content"></TextView>
</LinearLayout>

注意2个Activity都需要在Manifest文件中进行申明
分享到:
评论
1 楼 songfantasy 2011-02-23  
和这样的效果一样吗?

overridePendingTransition(R.anim.zoomin, R.anim.zoomout);

相关推荐

    新版Android开发教程.rar

    Android 是一个专门针对移动设备的软件集,它包括一个操作系统,中间件和一些重要的应用程序。 Beta 版 的 Android SDK 提供了在 Android 平台上使用 JaVa 语言进行 Android 应用开发必须的工具和 API 接口。 特性 ...

    工程硕士学位论文 基于Android+HTML5的移动Web项目高效开发探究

    Activity Activity是一个应用程序组件,提供一个屏幕,用户可以用来交互为了完成某项任务,是一个负责与用户交互的组件 SSH 为 Struts+Spring+Hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架。...

    Android 开发技巧

    9.31、把文件内容读出到一个字符串 245 9.32、扫描WIFI热点演示实例教程 246 9.33、调用GOOGLE搜索 249 9.34、调用浏览器 载入某网址 249 9.35、获取 IP地址 249 9.36、从输入流中获取数据并以字节数组返回 250 9.37...

    Android开发资料合集-World版!

    9.31、把文件内容读出到一个字符串 245 9.32、扫描WIFI热点演示实例教程 246 9.33、调用GOOGLE搜索 249 9.34、调用浏览器 载入某网址 249 9.35、获取 IP地址 249 9.36、从输入流中获取数据并以字节数组返回 250 9.37...

    android开发艺术探索高清完整版PDF

    《Android开发艺术探索》是一本Android进阶类书籍,采用理论、源码和实践相结合的方式来阐述高水准的Android应用开发要点。《Android开发艺术探索》从三个方面来组织内容。第一,介绍Android开发者不容易掌握的一些...

    Android开发艺术探索

    2.2.1 开启多进程模式 / 36 2.2.2 多进程模式的运行机制 / 39 2.3 IPC基础概念介绍 / 42 2.3.1 Serializable接口 / 42 2.3.2 Parcelable接口 / 45 2.3.3 Binder / 47 2.4 Android中的IPC方式 / 61 ...

    Android开发人员不得不收集的代码

    startActivities : 启动多个 Activity startHomeActivity : 回到桌面 getActivityList : 获取 Activity 栈链表 getLauncherActivity : 获取启动项 Activity getTopActivity : 获取栈顶 Activity ...

    Development.apk(Android Dev Tools)

    2.7 ANR starting an Activity(运行一个活动,但是应用无相应) 2.8 ANR recriving a broadcast Intent(接收一个广播意图,但是应用无响应) 2.9 ANR staring a Service(运行一个服务,但是应用无响应) 2.10 System ...

    计步器的实现

    android计步器的实现,自定义的一个弧形进度条,记步通过手机的传感器来实现,也就是说不支持传感器的机子(应该很老的了吧)就没有效果。看看效果图: 这里写图片描述这里写图片描述 自定义View public class ...

    ios开发记录

    //CGAffineTransformMakeRotation 方法的作用就是传进去一个角度(计量单位不是度,是弧度),方法内部帮你生成一个这个角度所对应的旋转矩阵 //rotate 旋转 CGAffineTransform a = ...

    !!!!ap6212a0_a33_sc3817r_验证通过_修正wifi的配置文件为nvram_ap6212.txt

    1、打开AP6212的BT,关闭rtl8723bs的BT(其它都是按照比对软件的字母顺序了): [ 3.141273] Bluetooth: HCI UART driver ver 2.2 [ 3.146210] Bluetooth: HCI H4 protocol initialized [ 3.151563] Bluetooth: HCI ...

    ap6212a0_a33_sc3817r_服务器验证通过_bt已经通了_wifi需要修改配置_需要再次验证_20170626_1549.7z

    1、打开AP6212的BT,关闭rtl8723bs的BT: [ 3.141273] Bluetooth: HCI UART driver ver 2.2 [ 3.146210] Bluetooth: HCI H4 protocol initialized [ 3.151563] Bluetooth: HCI BCSP protocol initialized [ 3.157154...

    ap6212a0_bb16v3_sina33验证通过BT的功能_wifi部分有问题_20170626_1148没有外层目录.7z

    1、打开AP6212的BT,关闭rtl8723bs的BT: [ 3.141273] Bluetooth: HCI UART driver ver 2.2 [ 3.146210] Bluetooth: HCI H4 protocol initialized [ 3.151563] Bluetooth: HCI BCSP protocol initialized [ 3.157154...

    ap6212a0_a33_sc3817r_神舟验证版本_借用nvram_ap6210这个配置文件_20170626_1834没有外层目录.7z

    1、打开AP6212的BT,关闭rtl8723bs的BT: [ 3.141273] Bluetooth: HCI UART driver ver 2.2 [ 3.146210] Bluetooth: HCI H4 protocol initialized [ 3.151563] Bluetooth: HCI BCSP protocol initialized [ 3.157154...

Global site tag (gtag.js) - Google Analytics