Android special Effects Album (10)--click the water ripple effect, the logic is clear and easy to implement

Source: Internet
Author: User

Android special Effects Album (10)--click the water ripple effect, the logic is clear and easy to implement

This time to do things, and the above is a bit similar, is to use a relatively simple logical thinking to achieve some of the more fun effects, and recently is relatively busy, so the speed of the blog update is also to see the time to deduce, but also to ensure that the appearance of a Wednesday, and now still small features, or some small entry-level blog-based I am not a very powerful person, a lot of details of the support is still not in place, so it has been made up, words not to say, to see the effect of today

It's easy to implement, so let's take a look at how he did it!

Onclickruning
 Packagecom.lgl.onclickruning;ImportAndroid.content.Context;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Color;ImportAndroid.graphics.Paint;ImportAndroid.graphics.Paint.Style;ImportAndroid.os.Handler;ImportAndroid.util.AttributeSet;ImportAndroid.util.Log;ImportAndroid.view.MotionEvent;ImportAndroid.view.View;/** * Tap water ripple Ripple animation effect * * @author LGL * */ Public  class runing extends View {    //Brushes    PrivatePaint Mpaint;//Inner circle width    Private intStrokewidth;//Center x    Private intCx//Center y    Private intCy//Radius    Private intRadius//Handler messages    Private Static Final intFLUSH =0; Public runing(context context, AttributeSet attrs) {Super(context, attrs);    Init (); }Private void Init() {//Initialize brushMpaint =NewPaint ();//anti-aliasingMpaint.setantialias (true);//Set colorMpaint.setcolor (Color.Blue);//Set HollowMpaint.setstyle (Style.stroke);//Set the width of the inner circleMpaint.setstrokewidth (Strokewidth);//Set Transparency 0-255Mpaint.setalpha (255);//Initial valueStrokewidth =0; Radius =0; }/** * * Draw * *    @Override    protected void OnDraw(Canvas canvas) {Super. OnDraw (canvas);//Draw a circleCanvas.drawcircle (CX, CY, RADIUS, mpaint); }/** * Touch Events * /    @Override     Public Boolean ontouchevent(Motionevent event) {//Judging gestures press and lift        Switch(Event.getaction ()) { CaseMotionevent.action_down:/** * Press down to start drawing a circle, that is, the ripples, so we first have to get to the coordinates of the press, in fact, we have to do this kind of operation of the development, must first get the coordinates in advance * /CX = (int) Event.getx (); cy = (int) event.gety (); LOG.I ("coordinates","center x:"+ CX +"Center y:"+ CY); Break; }//InitializeInit ();//SendHandler.sendemptymessage (FLUSH);return true; }/** * Refresh Status * *    Private void Flush() {//Radius +10 per timeRadius + =Ten;//The width of the line is One-fourth of the radius each timeStrokewidth = RADIUS/4;//Reset to brushesMpaint.setstrokewidth (Strokewidth);//color gradient, reduce the color value by 20 at a time        intNextalpha = Mpaint.getalpha ()- -;//Avoid equals negative        if(Nextalpha < -) {//Set directly to transparentNextalpha =0; }//Continue to reset to brushMpaint.setalpha (Nextalpha); }PrivateHandler Handler =NewHandler () { Public void Handlemessage(Android.os.Message msg) {Switch(msg.what) { CaseFLUSH://change parameter statusFlush ();//Refresh to execute our drawing methodInvalidate ();//Continue to verify transparency, as long as not 0, until transparent                if(Mpaint.getalpha ()! =0) {handler.sendemptymessagedelayed (FLUSH, -); } Break; }        }    };}
Layout_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <com.lgl.onclickruning.Runing        android:layout_width="match_parent"        android:layout_height="match_parent" /></RelativeLayout>

The code is very simple, our simple logic can be achieved, but do not underestimate this thinking, you can use this logic to achieve more interesting effects, here is looking forward to your excavation, hehe

demo:http://download.csdn.net/detail/qq_26787115/9433534

Android special Effects album (10)-Click the water ripple effect, the logic is clear and easy to implement

Related Article

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.