×

Android Ripple Effect | A New Way of Touch

Android Ripple Effect | A New Way of Touch

In : Technology By storytimes About :-2 years ago

Have you wondered when you touch your mobile screen you get a circular liquid effect that is called the Android ripple effect. This effect gives the confirmation to the user visually that the user interacted with the elements of UI and the click was successful. These UI elements may be in any form including Buttons, Layouts, TextViews, and ListViews.  

Ripple Effect code for Android

via

A newer version of Android Lollipop facilitates you with the touch feedback mechanism that is truly based on ripples that feature powerfully in Material design. The implementation of these ripples is slightly easier than the traditional techniques.

This feature is added to API 21 of Android 5.0 so it will not work on the previous versions.  The hierarchy of classes mentioned below:

1 java.lang.Object

2 ↳android.graphics.drawable.Drawable

3 ↳android.graphics.drawable.LayerDrawable

4 ↳android.graphics.drawable.RippleDrawable

Here we are discussing the implementation of Android Ripple Effect through the program by the use of the class RippleDrawable

The class will make the implementation of interface View.OnTouchListener

It will give callback public abstract boolean onTouch (View v, MotionEvent event)

An event touch is sent to the view, this would be called.

This procedure returns True if the user facing the event, otherwise it returns False.

The exact position of the provided state of the ripple determined by calling the setHotspot(float, float) along with the relevant attribute state identifier.

Android Ripple Effect Code : 

Android Ripple Effect Code

via

Here the coordinates for the current pointer are given by event.getX() and event.getY(). Also, by using object rippledrawable you can provide the required color.

Android Ripple Effect

via

Thus, If you found Android Ripple Effect | A New Way of Touch informative and interesting, please let us know through comment section below.   

Android Ripple Effect | A New Way of Touch