Image filtration with motion layout

Updated 31 January 2020

Save

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.

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home