
Introduction
In this article, we will learn how to use KenburnsView in Android using Kotlin. KenburnsView is an awesome Android library that provides an extension to ImageView that creates an immersive experience by animating its Drawable using the Ken Burns Effect.
Coding Part
I have divided the coding part into 3 steps as shown in the following.
- Creating a new project with Kotlin support.
- Setting up the project with KenburnsView Library.
- Implementing KenburnsView with Kotlin.
Step 1 - Creating a new project with Kotlin
- Open Android Studio and create a new project.
- Name the project as your wish and tick the Kotlin checkbox support.
- Then, select your Activity type (For Example, Navigation Drawer Activity, Empty Activity, etc.).

- Then, click the “Finish” button to create a new project in Android Studio.
Step 2 - Setting up the project with AndroidManifest
We will add the following lines to our app level build.gradle to add KenburnsView library to the project.
- dependencies {
- …
- implementation 'com.flaviofaria:kenburnsview:1.0.7'
- …
- }
- repositories {
- mavenCentral()
- }
Step 3 - Implementation of KenburnsView with Kotlin
- Let us start coding. Open your layout file. In my case, I have an XML included, i.e., content_main.xml. So, I have opened the content_main.xml file.
- Add the following lines of code into it.
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:layout_behavior="@string/appbar_scrolling_view_behavior"
- tools:context="com.androidmads.kenburnsview.MainActivity"
- tools:showIn="@layout/activity_main">
- <com.flaviofaria.kenburnsview.KenBurnsView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/img"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:src="@drawable/img1" />
- </android.support.constraint.ConstraintLayout>

Join the conversation! Your thoughts help the community grow.