Android RecyclerView Animations in Kotlin

Android RecyclerView Animations in Kotlin

Explanation of the animation properties, interpolators and Quick tutorial for recycler view animations with Android Studio and Kotlin

After coding the app, the functionality is not enough for a good-looking modern app. I think everyone is accepted that today, the app should consist of UI/UX, transitions-animations, and of course client-side. Today I will try to explain one of these aspects which is animations for recycler view items. I will be using Android Studio and Kotlin. Have fun :)

Let’s start with the basics

First of all, you need to create an anim folder to store your animation files.

Image for post

res(right-click)->New->Android Resource Directory

Image for post

We are setting the name “anim”

After that right-click the anim folder and create an “Animation Resources File”.

Explanation of the Properties

When you create the _Animation Resources File _you will see some properties in it. I will try to explain them and after that, we will be creating our animations.

Image for post

Translate

Translate is using primarily for moving the items on the x and y-axis. It has some attributes like these:

Image for post

FromXDelta _and fromYDelta_ represent which direction the item will come from. If you set a positive value for “fromXDelta”, it will come from the right side of the screen.ToDelta _attributes represent where the item will be stopping. Usually, I am using the _toDelta _attribute with 0% . Because even if you set it “-100%” when the animation duration finished the item will return to the screen and this does not look so good. And finally, the _“duration” is the animation time. Let's see an animation with just translate property.

Image for post

only anim

Alpha

Alpha is using for determining the opacity. This property is mainly using for fade in/out animations. Attributes are below:

Image for post

Fade in and out animations can be achieved using fromAlpha and toAlpha attributes. If you use the values like above you will achieve this animation.

Image for post

only anim

Rotate

The Rotate property, as can be understood from the name, is using for rotation animations for recycler view items.

Image for post

These attributes were confusing to me also in the beginning, because of that I will try to explain them as clear as possible. FromDegrees attribute is represented which degree the item will come from. Imagine the degrees and look at the image now. Items are coming from 270°and rotating clockwise. Pivot attributes are like pinning the item according to value. For example, if you set pivotX:100% and pivotY:0% and the fromDegrees: 90° it will pin the item on the top right corner and rotate it accordingly. The animation can be seen in the gif below.

Image for post

only anim

Scale

Scale property is using for scaling the items up and down. These attributes are more than others so let's dive in.

Image for post

Pivot attributes have a bit different function here. 50% value for both pivots represents the center of the item. I set it that way because I want to scale them up from the center. FromScale _and _ToScale attributes are using to scale the item. 1 for original size and 0 for beginning size. These attributes have an output like below.

Image for post

only anim

Setting up

holder.shopDetailParent.animation =
    AnimationUtils.loadAnimation(holder.itemView.context, R.anim.example_anims)

First of all, you need to define the view, which you want to animate, of the recycler view item in the adapter. After that, you can use that code snippet above on OnBindViewHolder to add your animations. I want to animate the whole item so I defined my _shopDetailParent _card view in the adapter. _“example_anims” _is my anim file so, you need to write your own file name to the code.

android kotlin mobile-apps programming developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Top Android App Development Companies | Hire Android App Developers USA | TopDevelopers.Co

Are you looking for an apt android app development firm for your business requirement? TopDevelopers.co has simplified the whole process of [hiring android app developers in the...

Android Mobile App Development Company in USA

AppClues Infotech is the best mobile app development company in New York that offers custom mobile app development & design services for Android and iOS.

Hire Android App Developer India - Mobile App Development India

Hire android app developer from India. We provide dedicated android app developer with flexible hiring models for your Android app development.

Hire Mobile App Developers in USA

AppClues Infotech is the best mobile app development company in New York that offers custom mobile app development & design services for Android and iOS.