How to create an animator slide up / down in XML for Android?

I tried to figure out how to create an animator (xml) that would trigger a slide and slide effect. How will it work? Thanks

+3
source share
1 answer

Create a folder animation in the res folder of the project. Now add slide_up.xml to the slide_up animation. Then add slide_down.xml for the slide animation.

Code for slide_down.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toYDelta="-1000" android:duration="1500"/> </set> 

Code for slide_up.xml:

 <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toYDelta="1000" android:duration="1500"/> </set> 

Then load the animation into the onCreate method as follows:

 Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up); 

To start it, attach it to the object you want to animate:

 ImageView img = (ImageView) findViewById(R.id.img); img.startAnimation(slideUp); 

Hope I helped you. :-)

+35
source

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


All Articles