Open In App
Related Articles

How to add KenBurns View in Android?

Improve Article
Save Article
Like Article

In this article, we will learn about how to add KenBurns View in android using java. KenBurns View is a useful library that is an extension of ImageView. It creates an immersive experience by animating its Drawable. We can use RandomTransitionGenerator to change the duration and acts as a interpolator of transitions. If we want to have more control over transition then we can implement our own TransitionGenerator.

  1. Add the support Library in build.gradle file and add dependency in the dependencies section. Through this KenBurns view can be directly added in xml files and have many inbuilt functions to customize it easily.

    dependencies {         
          implementation 'com.flaviofaria:kenburnsview:1.0.7'      

  2. Now add the following code in the activity_main.xml file. In this file we add KenBurns View in our layout.


    <?xml version="1.0" encoding="utf-8"?>
            app:layout_constraintTop_toTopOf="parent" />

  3. Now add the following code in the file. onClickListener is added with the kenBurns view. It makes the animation pause if it is in motion and vice versa.

    package org.geeksforgeeks.gfganimatedGradient;
    import android.os.Bundle;
    import android.view.View;
    import android.view.animation.AccelerateDecelerateInterpolator;
    import com.flaviofaria.kenburnsview.KenBurnsView;
    import com.flaviofaria.kenburnsview.RandomTransitionGenerator;
    public class MainActivity extends AppCompatActivity {
        KenBurnsView kenBurnsView;
        boolean moving = true;
        protected void onCreate(Bundle savedInstanceState)
            kenBurnsView = findViewById(;
            AccelerateDecelerateInterpolator interpolator
                = new AccelerateDecelerateInterpolator();
            // It is used to change the duration and
            // the interpolator of transitions
            RandomTransitionGenerator generator
                = new RandomTransitionGenerator(2000, interpolator);
            kenBurnsView.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v)
                    if (moving) {
                        moving = false;
                    else {
                        moving = true;

  4. Now compile and run the Android app.


Last Updated : 18 Feb, 2021
Like Article
Save Article
Similar Reads
Related Tutorials