Read More

Image filtration with motion layout

Image filtration with motion layout

In this blog, we are going to learn some cool features of motion layout. Image filtration is one of them.

MotionLayout:-

Motion Layout is a new class available in the ConstraintLayout 2.0 library. By using this class we can manage motion and widget animation in their application.

First of all, we have to implement dependency.

Implement this in your build.greadle (app) file.

Lets’s start some code:-

Now open your layout file in my case it is activity_main.xml.

In this layout file, We have MotionLayout as a view group and ImageFilterView as a child view. To perform Image filtration we need to use ImageFilterView.

In this layout file, we use layoutDescription attribute and parse a layout file motion demo_motion in it. Because layoutDesciption holds a reference of your motion_scene layout file.

This is the file that defines the type of motion/animation we want and what the starting/ending constraints are.

Here we defined a Transition (the animation) with duration & a start/endpoint to the layouts. And also a swipe Trigger on the image (with up direction) — which adds interactivity.

Specifying the saturation can be done simply by using a CustomAttribute:

Therefore we define saturation values 1 and 0 to get the filter effect.

As a result of saturation manipulation, we get a filter effect on our image.

We define two ConstraintSet children in our xml. Start and end positions of that image.

Finally, we have achieved Image filtration with motion layout.

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close