How to animate a view through an XML file? [closed]

0

How do I do animation in an imageview with the animation file in XML?

    
asked by anonymous 25.05.2017 / 23:50

1 answer

3

You need to start by seeing this: View Animation

Here's an example of how we can do Blink Animation . What is the type of animation that winks to view .

  

blink.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha
    android:duration="700"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toAlpha="1.0" />

</set>

All of these tags , fromAlpha , interporlator , ...) are explained in the link I sent it to you.

  • Duration : Defines how long the animation will refresh, ie the longer, slower the effect will be.

  • fromAlpha : is responsible for making the view invisible.

  • toAlpha : it will lighten the view.

To apply the animation to any view, do this:

yourImageView.setAnimation(AnimationUtils.loadAnimation(this, R.anim.blink)).

To pause the animation in progress, do this:

yourImageView.clearAnimation();

You can find more examples of animations at: Demos API

    
26.05.2017 / 00:12