activity切换动漫
作者:互联网
activity切换动漫
在onCreate()
函数中的setContentView(R.layout.activity_main);
前面添加getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
表明要申请活动转换动画
然后在下面添加活动离开以及活动进入动画getWindow().setEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.explode));
和getWindow().setExitTransition(TransitionInflater.from(this).inflateTransition(R.transition.fade));
其中R.xxxx
是自定义文件,自定义活动方式
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main2);
getWindow().setEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.explode));
getWindow().setExitTransition(TransitionInflater.from(this).inflateTransition(R.transition.fade));
}
这样便可以进行Activity之间的动画切换
之后在res/transition
文件夹中创建文件,下面是我的一些文件转场方式:
explode
<?xml version="1.0" encoding="utf-8"?>
<explode xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"/>
fade
<?xml version="1.0" encoding="utf-8"?>
<fade xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"/>
slide_bottom
<?xml version="1.0" encoding="utf-8"?>
<slide xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:slideEdge="bottom"/>
slide_left
<?xml version="1.0" encoding="utf-8"?>
<slide xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:slideEdge="start"/>
slide_right
<?xml version="1.0" encoding="utf-8"?>
<slide xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:slideEdge="end"/>
slide_top
<?xml version="1.0" encoding="utf-8"?>
<slide xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:interpolator="@android:interpolator/accelerate_cubic"
android:slideEdge="top" />
标签:transition,TransitionInflater,动漫,slide,切换,inflateTransition,getWindow,activity 来源: https://www.cnblogs.com/Yunrui-blogs/p/12509952.html