Animation settings at screen transition

I've been posting a lot lately. I learned something new, so I'd like to write an article immediately.

Animation settings at screen transition

I will explain about. Originally, if you switch the activity, another activity will appear from the bottom, but I wanted to change it so that the screen appears from right to left, so I made an article because I was able to investigate various things. The image can be viewed from the URL below. https://media.giphy.com/media/wJ63LgRpC4zDxst0SN/giphy.gif github https://github.com/minton0721/SlideProject You can check the actual behavior by downloading this.

STEP1 Edit Styles.xml

styles.xml


<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
        <!--style applied theme-->
    <style name="Animation" parent="AppTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:windowAnimationStyle">@style/AnimationActivity</item>
    </style>
    <!--Style to animate the activity-->
    <style name="AnimationActivity" parent="android:Animation.Activity">
        <item name="android:activityOpenEnterAnimation">@anim/open_enter</item>
        <item name="android:activityOpenExitAnimation">@anim/open_exit</item>
        <item name="android:activityCloseEnterAnimation">@anim/close_enter</item>
        <item name="android:activityCloseExitAnimation">@anim/close_exit</item>
    </style>

Since the activity animation is a windowAnimationStyle element, I will add it. When OpenEnter and OpenExit are when the activity is displayed, and when CloseExit and CloseEnter are when the activity disappears. Since each has the current activity and the next activity, a total of 4 will be specified.

STEP2 Create 4 files

If it remains in the previous state, an error will occur because the specified file does not exist. Create a directory called anim and create 4 files there.

anim/open_enter.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%"
        android:toXDelta="0%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"/>
</set>

anim/open_exit.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0%"
        android:toXDelta="-100%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"/>
</set>

anim/close_enter.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%"
        android:toXDelta="0%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"/>
</set>

anim/close_exit.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0%"
        android:toXDelta="100%"
        android:duration="300"
        android:fillAfter="true"
        android:fillEnabled="true"/>
</set>

STEP3 Edit manifests.xml

manifests.xml


<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Animation"> <!--← Change this part from Theme to Animation-->

If you just want to change the method of switching activities, you should be able to do it this way! Reference URL http://furudate.hatenablog.com/entry/2013/06/12/214126

It was very helpful. Thank you! !!

Recommended Posts

Animation settings at screen transition
Screen transition method
Screen transition memorandum
Login screen displayed at localhost: 8080
How to transition from the [Swift5] app to the iPhone settings screen
[Swift] Simple screen transition summary
[Android] Exit the activity of the transition source at the time of screen transition
Android development ~ Screen transition (intent) ~
Screen transition Information transfer memorandum
Screen transition with swing, java
Screen transition using Intent in Kotlin
[Rails] How to prevent screen transition
Screen transition by Post method [Java]
[Java Swing] Screen transition by CardLayout