Build awesome animations with 7 lines of code using ConstraintLayout
You can find a sample app on GitHub here:
sample app in GitHub
The tutorial is about animating layout changes using the android's transition framework with constraints in a ConstraintLayout.
To begin with, let's see a preview of the animation:
preview of the animation |
There are some things I would like to point out about this animation...
Layout files
As you can see from the sample app, there are basically 2 layouts: the starting layout (at the beginning of the animation) and the ending layout (at the end of the animation).The two layouts are almost identical (they have the same widgets), but with different constraints.
For example in the first layout the title and subtitle have the right constraint set on the left of the ImageView, so they are just outside the screen and therefore not visible. This is their starting position at the beginning of the animation.
The same applies to the TextView containing the description. In the first layout it has its top constraint set to the bottom of the ImageView, so it's just outside the screen and therefore not visible.
In the second layout the same widgets are visible because they use different constraints: that's the final position in the animation.
ConstraintSet
This class allows you to define programmatically a set of constraints to be used with ConstraintLayout. It lets you create and save constraints, and apply them to an existing ConstraintLayout.In the example, using the method clone() we can assign to the ConstraintSet the constraints of the second layout.
Transition framework
The animation makes use of the Android's transition framework. To be more specific, it uses a transition without scenes using the method "beginDelayedTransition" as described here:Apply a transition without scenes
The sample uses the ChangeBounds transition (move and resize views).
Animation
The animation works as follows:- we retrieve the constraints from the second layout and store them in a ConstraintSet
- we define a Transition (ChangeBounds) with an interpolator and execution time
- we invoke the method "beginDelayedTransition" to mark the beginning of the animation
- we make the changes that must be animated: these simply consist of applying the constraints of the second layout to the first layout
One thing to notice is that the two layouts are identical except for the constraints, which define the position of the widgets. By animating the constraints we can animate the position of the widgets.
Another thing to notice is that the transition is always applied to the first layout (named "constraint"): the first time we apply the constraints of the second layout, the secont time we apply the constraints of the first layout, and so on...
" Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
ReplyDelete"
iphone repair chennai | apple iphone service center in chennai | iphone service chennai | apple iphone service center in chennai
I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
ReplyDeleteData science Course Training in Chennai | No.1 Data Science Training in Chennai
RPA Course Training in Chennai | No.1 RPA Training in Chennai
I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
ReplyDeleteAuthorized iphone service center in Chennai | iphone service center in chennai | Mobile service center in chennai | Authorized iphone service center in Chennai | iphone service center in chennai | Authorized iphone service center in Chennai | iphone battery replacement in chennai
Nice information for a new blogger…it is really helpful
ReplyDeleteMobile phone Battery replacement | Mobile phone unlocking service | 100% genuine mobile parts | Mobile service center in chennai | Dell laptop service center in chennai | Mobile phone glass replacement
“Useful post”
ReplyDeleteMobile phone Battery replacement in chennai | Mobile phone unlocking service in chennai | 100% genuine mobile parts | Tab service center in chennai | 100% genuine mobile parts | Mobile phone glass replacement
“Useful post”
ReplyDeletepolitics news chennai | latest news in tamil | politics news chennai | latest news in sunnews | politics speech tamil | NetCab
This is a great post,as always like to learn for mobile development.I’am so enjoying this blog.You are the best writer!
ReplyDeleteNetCab | election news 2019 | election news 2019 | tamil news live youtube | politics speech tamil
It's a shame you don't have a donate button! I'd definitely donate to this fantastic blog! I suppose for now i'll settle for bookmarking and adding your RSS feed to my Google account. I look forward to new updates and will talk about this site with my Facebook group. Talk soon!
ReplyDeleteapp entwickler berlin
Very nice and informative blog
ReplyDeleteAndroid App Development Company USA
Custom Software Development Company USA
Software Development Company USA