android中的动画之变化动画事例4

今天我在这里说下Activity切换动画。Activity切换动画指的是Activity跳转的动画,分别分为:一个activity退出的动画,另一个activity进入的动画。

在android2.0之后,就有了一个方法来给我们实现这种效果--overridePendingTransition(int,int)。从这个方法中,我们可以看出overridePendingTransition方法需要我们传递2个参数,第一个参数是第二个Activity进入的动画,第二个参数是第一个Activity退出的动画。话不多说了,我们直接来看代码

anim文件下的代码

1.in.xml代码--第二个Activity进入的动画

1 <?xml version="1.0" encoding="utf-8"?>
2 <set xmlns:android="http://schemas.android.com/apk/res/android">
3     <alpha
4         android:fromAlpha="0.0"
5         android:toAlpha="1.0"
6         android:duration="3000"
7        />
8
9 </set>

2.out.xml代码--第一个Activity退出的动画

1 <?xml version="1.0" encoding="utf-8"?>
2 <set xmlns:android="http://schemas.android.com/apk/res/android">
3     <alpha
4         android:fromAlpha="1.0"
5         android:toAlpha="0.0"
6         android:duration="3000"
7         />
8
9 </set>

布局文件下的代码

1.MainActivity的布局文件代码

xml代码

 1  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical"
 6     tools:context="com.example.Tween_Animation.Alpha_MainActivity" >
 7
 8     <Button
 9         android:id="@+id/button_scale"
10         android:layout_width="fill_parent"
11         android:layout_height="wrap_content"
12         android:text="@string/button_stringScaleAnimation" />
13
14     <LinearLayout
15         android:gravity="center"
16         android:layout_width="fill_parent"
17         android:layout_height="fill_parent"
18         android:orientation="vertical" >
19
20         <ImageView
21             android:id="@+id/imageview_scale"
22             android:layout_width="wrap_content"
23             android:layout_height="wrap_content"
24             android:src="@drawable/ic_launcher" />
25     </LinearLayout>
26
27 </LinearLayout>

2.MainActivity2布局代码

xml代码

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6     <ImageView
 7         android:layout_width="fill_parent"
 8         android:layout_height="match_parent"
 9         android:background="@drawable/ic_launcher"
10         />
11 </LinearLayout>

MainActivity的代码

JAVA代码

 1 package com.example.Demo4;
 2
 3 import com.example.androidanimation.R;
 4
 5 import android.app.Activity;
 6 import android.content.Intent;
 7 import android.os.Bundle;
 8 import android.view.View;
 9 import android.view.View.OnClickListener;
10 import android.widget.Button;
11 import android.widget.ImageView;
12
13 public class MainActivity extends Activity implements OnClickListener{
14     private Button button = null;
15     private ImageView imageview = null;
16     protected void onCreate(Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18         setContentView(R.layout.activity_main);
19         button = (Button) findViewById(R.id.button_scale);
20         imageview = (ImageView) findViewById(R.id.imageview_scale);
21         button.setOnClickListener(this);
22     }
23     public void onClick(View v) {
24         Intent intent = new Intent(MainActivity.this,MainActivity2.class);
25         startActivity(intent);
26         overridePendingTransition(R.anim.in, R.anim.out);
27     }
28
29 }

MainActivity2的代码

JAVA代码

 1 package com.example.Demo4;
 2
 3 import com.example.androidanimation.R;
 4
 5 import android.app.Activity;
 6 import android.os.Bundle;
 7
 8 public class MainActivity2 extends Activity{
 9     protected void onCreate(Bundle savedInstanceState) {
10         super.onCreate(savedInstanceState);
11         setContentView(R.layout.main);
12     }
13 }
时间: 2024-07-29 13:25:51

android中的动画之变化动画事例4的相关文章

android中的动画之变化动画事例1

前面我已经说了变换动画,并且变换动画中分为4种情况:透明度动画.旋转动画.缩放动画.位移动画. 今天我来说说关于使用变换动画中的4种类型来实现它们的糅合. 我在这里主要使用了一个Animation对象中的一个监听方法--setAnimationListener.这个方法里面只有一个参数,安卓api给出的这个方法的完整形态-- void android.view.animation.Animation.setAnimationListener(AnimationListener listener)

android中给Dialog设置的动画如何自定义修改参数

============问题描述============ 在android中给Dialog设置动画的方法我只找到Dialog.getWindow().setWindowAnimation(int resID); 这样不是只能在styles里用xml定义动画吗? 但是我现在想要先用程序计算出一个屏幕上的点,在让Dialog从该点开始执行scaleAnimation. 我如何给我Dialog的动画设置起始点之类的参数呢? ============解决方案1============ 自定义一个dial

android中的动画之变化动画事例2

之前,我已经说了下,关于变换动画的糅合.在这里,我将说的是,写一个动画集AnimationSet(我们知道,在JAVA中有set容器,而set容器的特点就是:1.无序2.不含重复元素.相当于是数学中的集合)用来存放多个Animation对象,这是JAVA代码的方法,还有一个方法就是在anim下的xml代码写一个集合,用来存放多个动画,我在这里用的是第二种方法 anim文件下的xml代码 xml代码 1 <?xml version="1.0" encoding="UTF-

android中的动画之变化动画事例3

今天我来说下,关于动画的重复的使用. 首先,我在这里使用的是JAVA代码来实现的,创建了一个AlphaAnimation来设置动画的属性.话不多说,直接贴代码 布局文件代码 xml代码 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layou

Android组件Activity中的View绘画和动画(Animation)是否会重画?

Activity 就是Android中的活动,是Android系统中唯一一个可见组件. Activity中官网中有一句话: The visible lifetime of an activity happens between a call to onStart() until a corresponding call to onStop() 这句话的意思是可以看见Activity的生命周期是从 调用onStart()方法开始 直到调用onStop()方法.这句话开始我就理解错误了.因为设置Ac

Android中的补间动画(tween)的简单使用

相对帧动画,补间动画(tween)可以这么理解:我们不必像帧动画一样指定动画的每一帧,只需定义一个动画的开始和结束关键帧,而中间变化的帧由系统帮我们计算. tween动画可以分为下面几种: AlphaAnimation(透明渐变动画): 示例:res/anim/alpha.xml <?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.andr

Android中的动画学习总结

android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动画. 具体实现步骤如下: 第一:新建一个drawable资源 以animation-list 为根节点创建资源文件. 第二:给ImageView或者其他View设置关联drawable.可以作为background或者src. 第三:在java代码中,通过View.getBackground():或

Android中的动画具体解释系列【2】——飞舞的蝴蝶

这一篇来使用逐帧动画和补间动画来实现一个小样例,首先我们来看看Android中的补间动画. Android中使用Animation代表抽象的动画类,该类包含以下几个子类: AlphaAnimation:透明改变动画. ScaleAnimation:大小缩放动画. TranslateAnimation:位移变化动画. RotateAnimation:旋转动画. 我们以下使用位移动画和逐帧动画来实现这个小样例.先看看执行效果: 蝴蝶挥动翅膀的逐帧动画文件: <?xml version="1.0

Android中的动画机制

1 逐帧动画 逐帧动画 就是一系列的图片按照一定的顺序展示的过程. 逐帧动画很简单, 只需要在drawable中或者anim中定义一个Animation-list 其中包含多个item,每个item中包含一个图片 和duration eg: <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk