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));
        
        startActivity(new Intent(FirstActivity.this, SecondActivity.class),
                    ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
        
    }
    

这样便可以进行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" />

posted @ 2020-03-17 12:58  野生的Lemon柠檬  阅读(144)  评论(0编辑  收藏  举报

呱呱呱呱呱🐸