Water Ripple effect---3 ring ripple

Source: Internet
Author: User



Import Android.content.context;import Android.graphics.bitmap;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.matrix;import Android.graphics.paint;import Android.graphics.porterduff;import Android.graphics.porterduffxfermode;import Android.graphics.Bitmap.Config; Import Android.os.handler;import android.os.message;import android.util.displaymetrics;import android.util.Log; Import android.view.view;import android.view.viewgroup;import android.widget.imageview;/** * Water Ripple View * @author Alan * * * * public Class Waterview Extends view{/** * Opacity (fully transparent: 0) */private int radius1;private int radius2;private int Radius3;priva  te int alpha1;private int alpha2;private int alpha3;private paint paint1;private paint paint2;private paint paint3;private int widthscreen;private int heightscreen;private Handler mhandler;/** * Picture diameter */private static final int MIN = 50; Public Waterview (Context Context,bitmap source) {super (context); init ();//Gets the screen's wide height displaymetrics dm = getresourCES (). Getdisplaymetrics (); widthscreen = Dm.widthpixels;heightscreen = Dm.heightpixels;mhandler = new Handler () {@ overridepublic void Handlemessage (Message msg) {super.handlemessage (msg); switch (msg.what) {case 0:flushstate (); WaterView.this.invalidate (); if (Alpha1 ==0 | | ALPHA2 ==0 | | Alpha3 ==0) {log.i ("TAG", "alpha1-->" +alpha1+ "alpha2-->" +alpha2+ "alpha3-->" +ALPHA3); Mhandler.sendemptymessage (1);} Else{mhandler.sendemptymessagedelayed (0, 50);} Break;case 1:initsimple (); WaterView.this.invalidate (); mhandler.sendemptymessage (0); break;default:break;}}; Mhandler.sendemptymessage (0);} @Overrideprotected void onmeasure (int widthmeasurespec, int heightmeasurespec) {//TODO auto-generated method Stubsuper.onmeasure (Widthmeasurespec, heightmeasurespec);} @Overrideprotected void OnDraw (canvas canvas) {log.i ("TAG", "OnDraw ..."); Super.ondraw (canvas);//Draw round// C1 (min circle) canvas.drawcircle (WIDTHSCREEN/2, This.getheight ()/2, RADIUS1, paint1);//c2canvas.drawcircle (WIDTHSCREEN/2, This.getheight ()/2, RADIUS2,PAINT2);//c3canvas.drawcircle (WIDTHSCREEN/2, This.getheight ()/2, RADIUS3, PAINT3);} private void Init () {alpha1 = 255;radius1 = min/2;alpha2= 175;radius2 = min/2 + 80;alpha3 = 95;RADIUS3 = MIN/2 + 160 ; Initpaint ();} private void Initsimple () {if (alpha1 = = 0) {alpha1 = 255;radius1 = Min/2;paint1.setcolor (Color.Blue);} if (alpha2 = = 0) {alpha2 = 255;radius2 = Min/2;paint2.setcolor (Color.Blue);} if (Alpha3 = = 0) {alpha3 = 255;radius3 = Min/2;paint3.setcolor (Color.Blue);} Paint1.setalpha (ALPHA1);p Aint2.setalpha (ALPHA2);p Aint3.setalpha (ALPHA3);} private void Flushstate () {radius1 +=5;alpha1-=5;//control speed, the larger the value, the quicker the ring expands radius2 +=5;alpha2-=5;radius3 +=5;alpha3-=5;if ( Alpha1 <= 0) {alpha1 = 0;} if (alpha2 <= 0) {alpha2 = 0;} if (alpha3 <= 0) {alpha3 = 0;} Paint1.setalpha (ALPHA1);p Aint2.setalpha (ALPHA2);p Aint3.setalpha (ALPHA3);} private void Initpaint () {//new brush paint1 = new paint ();p Aint1.setantialias (TRUE);//Set anti-aliasing paint1.setstrokewidth (float ) 1);//Set the line width 1paint1.setstyle (Paint.Style.STROKE);//Set Hollow brush, ring-shaped Paint1.setalpha (alpha1);p Aint1.setcolor (Color.Blue);//define Brush 2paint2 = new paint (); Paint2.setantialias (TRUE);//Set anti-aliasing paint2.setstrokewidth ((float) 1);//Set line width 1paint2.setstyle (Paint.Style.STROKE);// Set the hollow brush, Draw Paint2.setalpha (ALPHA2) in a circular manner;//define Brush 3paint3 = new paint ();p Aint3.setantialias (TRUE);// Set the antialiasing paint3.setstrokewidth ((float) 1),//Set the line width 1paint3.setstyle (Paint.Style.STROKE),//Set the hollow brush, draw the paint3.setalpha in a ring way (ALPHA3);}}


Water Ripple effect---3 ring ripple

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.