Search code examples
androidanimationtranslate-animation

Define xml animation into Java


Is it possible to write slide_out_left animation using java?

Here is my animation xml.

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


Solution

  • yes it is possible:

    view.animate().translationX(_amount_).setDuration(_time in ms_).start();
    

    So, you will have to calculate translation distance by yourself. Note: if you translate to 0 later, after some other translations - it will move to starting position.

    To complete slide in effect try to use withStartAction also.