Android实现Activity界面切换添加动画特效的方法
作者:shichen2014 时间:2021-07-11 08:02:35
本文以实例形式展示了Android实现Activity界面切换添加动画特效的方法,对于Android程序设计人员来说有很好的参考借鉴价值。具体方法如下:
了解Android程序设计的人应该知道,在Android 2.0之后有了overridePendingTransition(),其中里面两个参数,一个是前一个activity的退出,另一个activity的进入。
现看看下面这段示例代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.SplashScreen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent mainIntent = new Intent(SplashScreen.this, AndroidNews.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
overridePendingTransition(R.anim.mainfadein,
R.anim.splashfadeout);
}
}, 3000);
}
上面的代码只是闪屏的一部分。
getWindow().setWindowAnimations(int);
这可没有上个好但是也可以 。
实现淡入淡出的效果:
overridePendingTransition(Android.R.anim.fade_in,android.R.anim.fade_out);
由左向右滑入的效果:
overridePendingTransition(Android.R.anim.slide_in_left,android.R.anim.slide_out_right);
实现zoomin和zoomout,即类似iphone的进入和退出时的效果:
overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
新建zoomin.xml文件:
<?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>
新建zoomout.xml文件:
<?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>
相信本文所述示例对大家的Android程序设计有一定的借鉴价值。
标签:Android,Activity,动画
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java迭代器原理及迭代map的四种方式
2021-08-27 12:04:30
java 画pdf用itext调整表格宽度、自定义各个列宽的方法
2021-07-12 04:16:10
![](https://img.aspxhome.com/file/2023/6/75766_0s.jpg)
java实现图书馆管理系统
2023-12-10 15:50:29
Java深入理解代码块的使用细节
2023-06-13 04:45:59
![](https://img.aspxhome.com/file/2023/0/76610_0s.png)
C#中Params的用法
2023-06-03 22:23:27
Java编写迷宫小游戏
2021-08-06 12:53:33
![](https://img.aspxhome.com/file/2023/5/62975_0s.jpg)
深入浅出讲解Java集合之Collection接口
2023-05-27 05:53:38
![](https://img.aspxhome.com/file/2023/2/89622_0s.png)
Android编辑框EditText与焦点变更监视器及文本变化监视器实现流程详解
2021-06-21 04:48:14
![](https://img.aspxhome.com/file/2023/6/98676_0s.png)
SpringBoot的异常处理流程是什么样的?
2021-07-09 17:54:40
![](https://img.aspxhome.com/file/2023/4/81894_0s.png)
详谈hibernate,jpa与spring data jpa三者之间的关系
2022-08-04 22:35:57
![](https://img.aspxhome.com/file/2023/9/76479_0s.jpg)
C#中WPF颜色对话框控件的实现
2023-04-13 06:09:41
![](https://img.aspxhome.com/file/2023/7/88437_0s.png)
Java中super和this关键字详解
2023-03-18 15:49:08
![](https://img.aspxhome.com/file/2023/4/63054_0s.png)
SpringBoot浅析Redis访问操作使用
2022-09-26 02:09:18
![](https://img.aspxhome.com/file/2023/4/80314_0s.png)
Java对zip,rar,7z文件带密码解压实例详解
2023-11-29 05:08:32
![](https://img.aspxhome.com/file/2023/4/60674_0s.png)
关于BufferedReader读取文件指定字符集问题
2023-09-03 11:10:28
java String的intern方法
2021-07-05 03:23:52
Java Socket编程(五) 简单的WEB服务器
2023-05-23 01:00:04
android 多点触摸图片缩放的具体实现方法
2023-03-14 05:49:31
基于C#的图表控件库 ScottPlot编译visual studio 2022
2022-05-02 10:24:13
![](https://img.aspxhome.com/file/2023/2/96382_0s.jpg)
Java数据结构之链表的增删查改详解
2023-08-13 07:48:40
![](https://img.aspxhome.com/file/2023/7/80837_0s.png)