Android Code - How do i create transitions between an Activity in Android studio Application?

How to create transitions between an activity in an android studio application?




Initial setup for Android Studio (Text):

First we need to know how to create /res/animation folder:
Steps:
1 - In the project pane - there are defaults on the left side of the screen, Choose "Project View".
2 - If the upper left corner of the pane days "Android" and has a robot icon, click it and select "Project".
3 - Right Click and select the "res" folder in the main source set tree and choose "new -> android resource file".
4 - In the pop up dialog enter a name for the file ,select type -animator, add qualifiers.
5 - Click "done" once you have set it up and your new file should be under "/res/***".

Credit to stackoverflow . Click here

Then we need to write the code for the transition.

There are two files which needs to be created :

animation1.xml -> (moved towards left - starting at right. This actions the 2nd activity which is being called  )

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="600"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="600" />
</set>


2 - animation2 .xml (this file will action the 1st activity which is calling the transition . 1st activity will be animated and then the 2nd activity will load )

<?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="600" />
</set>

The code works fine. I tested on my phone .

This is the result :




Hopefully u enjoyed watching this video .

Please like ,subscribe and Follow for more.

Thank you

Comments

Popular posts from this blog