Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to add animation between activity in android

You can overwrite your default activity animation and it perform better 
than overridePendingTransition. I use this solution that work for every 
android version. Just copy paste 4 files and add a 4 lines style as below:

Create a "CustomActivityAnimation" and add this to your base Theme 
by "windowAnimationStyle".

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:windowAnimationStyle">@style/CustomActivityAnimation</item>

</style>

<style name="CustomActivityAnimation" parent="@android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/slide_in_right</item>
    <item name="android:activityOpenExitAnimation">@anim/slide_out_left</item>
    <item name="android:activityCloseEnterAnimation">@anim/slide_in_left</item>
    <item name="android:activityCloseExitAnimation">@anim/slide_out_right</item>
</style>

Then Create anim folder under res folder and then create this four animation 
files into anim folder:

slide_in_right.xml
  <?xml version="1.0" encoding="utf-8"?>
  <set xmlns:android="http://schemas.android.com/apk/res/android">
      <translate android:fromXDelta="100%p" android:toXDelta="0"
          android:duration="@android:integer/config_mediumAnimTime"/>
  </set>
  
slide_out_left.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%p"
          android:duration="@android:integer/config_mediumAnimTime"/>
  </set>

slide_in_left.xml
  <?xml version="1.0" encoding="utf-8"?>
  <set xmlns:android="http://schemas.android.com/apk/res/android">
      <translate android:fromXDelta="-100%p" android:toXDelta="0"
          android:duration="@android:integer/config_mediumAnimTime"/>
  </set>

slide_out_right.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%p"
          android:duration="@android:integer/config_mediumAnimTime"/>
  </set>
Comment

PREVIOUS NEXT
Code Example
Java :: onclick listener android 
Java :: spigot send player action bar message 1.8 
Java :: find minimum number in array java 
Java :: how do i print text in java 
Java :: how to use scanners in java 
Java :: java copy array 
Java :: get text from a jtextfield 
Java :: inorder, PreOrder, PostOrder java 
Java :: java loop array backwards 
Java :: java restart program 
Java :: java sealed class 
Java :: how to read a excel file in java 
Java :: java File Separator 
Java :: in java how to throw exception from function 
Java :: change image on button click android studio 
Java :: mobile number validation to edittext in android 
Java :: Who made java ? 
Java :: how to solve Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
Java :: java 8 map foreach 
Java :: java insert char in string at index 
Java :: spigot disable join message 
Java :: reverse a integer in java 
Java :: timestamp java jpa 
Java :: integer to string java 
Java :: collatz conjecture 
Java :: Getting Pending intent for 12 version 
Java :: jtable get get row 
Java :: how to get the max value of an array java 
Java :: java stack methods 
Java :: android studio change launcher icon 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =