Create animations while running on Android

I can use the xml file as below

<set xmlns:android="http://schemas.android.com/apk/res/android" 
     android:interpolator="@android:anim/decelerate_interpolator">

 <translate android:fromXDelta="100%" android:toXDelta="0%" android:duration="500" />

</set>

and download this xml from code like AnimationUtils.loadAnimation (mContext, com ..... R.anim.slidein)

everything works perfectly

But now for some reason I need to do the same without using XML, how to create the same animation using only code, I tried something like this

TranslateAnimation in = new TranslateAnimation (1.0f, 0.0f, 0.0f, 0.0f);


    in.setInterpolator (AnimationUtils.loadInterpolator (mContext,
                        android.R.anim.accelerate_interpolator));

    in.setDuration (500);

but it doesn’t work, nothing revives

I think the problem is related to percentages, in xml I specified percentages, but in the TranslateAnimation constructor, how to specify percentages

+3
2

. (). . , :

TranslateAnimation in = new TranslateAnimation(
    Animation.RELATIVE_TO_SELF, 1.0f,
    Animation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f, 0, 0.0f);

. Animation.RELATIVE_TO_PARENT .

+5

( 'p'):

 <translate android:fromXDelta="100%p" android:toXDelta="0%p" android:duration="500" />
0

Source: https://habr.com/ru/post/1774775/


All Articles