Android切换Activity时的淡入动画和缩小动画

http://www.eoeandroid.com/thread-229733-1-1.html

实现在Activity切换过程中的淡入和缩小的动画效果,先创建一个主Activty布局,主Activity有两个按钮一个是实现切换的淡入效果,一个是实现缩小效果。

main.xml布局如下:
代码片段,双击复制
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
<?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" >
<TextView
android:layout_width= "fill_parent"
android:layout_height= "wrap_content"
android:text= "本程序实现在Activity切换过程中的淡入和放大的动画效果!" />
<Button
android:id= "@+id/fadein"
android:layout_width= "fill_parent"
android:layout_height= "wrap_content"
android:text= "Fade in" />
<Button
android:id= "@+id/zoomin"
android:layout_width= "fill_parent"
android:layout_height= "wrap_content"
android:text= "Zoom in" />
</LinearLayout>


主Activity内容:
代码片段,双击复制
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.xiaochun91103;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
 
public class MainActivity extends Activity {
/** Called when the activity is first created. */
private Button fadeIn, zoomOut;
 
@Override
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.main);
 
fadeIn = (Button) findViewById(R.id.fadein);
fadeIn.setOnClickListener( new OnClickListener() {
 
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity( new Intent(MainActivity. this , ShowActivity. class ));
overridePendingTransition(R.anim.fade, R.anim.hold); // 切换Activity的过渡动画
}
});
 
zoomOut = (Button) findViewById(R.id.zoomout);
zoomOut.setOnClickListener( new OnClickListener() {
 
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity( new Intent(MainActivity. this , ShowActivity. class ));
overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
}
});
}
}


动画效果的xml如下:
fade.xml
代码片段,双击复制
01
02
03
04
05
06
<?xml version= "1.0" encoding= "utf-8" ?>
<alpha xmlns:android= "http://schemas.android.com/apk/res/android"
android:interpolator= "@android:anim/accelerate_interpolator"
android:fromAlpha= "0.0"
android:toAlpha= "1.0"
android:duration= "@android:integer/config_longAnimTime" />


hold.xml
代码片段,双击复制
01
02
03
04
05
06
<?xml version= "1.0" encoding= "utf-8" ?>
<translate xmlns:android= "http://schemas.android.com/apk/res/android"
android:interpolator= "@android:anim/accelerate_interpolator"
android:fromXDelta= "0"
android:toXDelta= "0"
android:duration= "@android:integer/config_longAnimTime" />


zoom_enter.xml
代码片段,双击复制
01
02
03
04
05
06
07
08
09
10
11
12
<?xml version= "1.0" encoding= "utf-8" ?>
<set xmlns:android= "http://schemas.android.com/apk/res/android"
android:interpolator= "@android:anim/decelerate_interpolator" >
<scale
android:fromXScale= "2.0"
android:toXScale= "1.0"
android:fromYScale= "2.0"
android:toYScale= "1.0"
android:pivotX= "50%p"
android:pivotY= "50%p"
android:duration= "@android:integer/config_mediumAnimTime" />
</set>


zoom_exit.xml
代码片段,双击复制
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
<?xml version= "1.0" encoding= "utf-8" ?>
<set xmlns:android= "http://schemas.android.com/apk/res/android"
android:interpolator= "@android:anim/decelerate_interpolator"
android:zAdjustment= "top" >
<scale
android:fromXScale= "1.0"
android:toXScale= ".5"
android:fromYScale= "1.0"
android:toYScale= ".5"
android:pivotX= "50%p"
android:pivotY= "50%p"
android:duration= "@android:integer/config_mediumAnimTime" />
<alpha
android:fromAlpha= "1.0"
android:toAlpha= "0"
android:duration= "@android:integer/config_mediumAnimTime" />
</set>


另外showActivity仅仅做一个界面不做任何操作,所以用户可以随便编一个界面,用来在Activity的切换中显示过渡的动画。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值