Before I saw the effect of a water wave on a Samsung phone after tapping the screen, I tried to write a similar result.
Implement a custom view and implement the constructor method
public class MyView extends View {
Public MyView (Context context) {
Super (context);
TODO auto-generated Constructor stub
}
Public MyView (context context, AttributeSet Attrs) {
Super (context, attrs);
TODO auto-generated Constructor stub
}
}
If you want to draw a circle, you need to set the radius of the ring, the stroke width (if filling is not required), the coordinates of x and Y, because you need to disappear after clicking on the screen, so add transparency
So we're going to create a new bean to implement these
public class Mybean {
int Alpha; Transparency
int X; X-coordinate
int Y; Y-coordinate
float width; Stroke width
float radius; Radius
Paint paint; Brush
}
Next is to get a click on the screen after the event, the idea is very clear, after tapping the screen, first set the radius of the drawn circle is 0, the transparency is the maximum value of 255, the stroke width is freely set by personal preference
@Override
public boolean ontouchevent (Motionevent event) {
Super.ontouchevent (event);
Switch (event.getaction ()) {
Case Motionevent.action_down:
After tapping the screen, set the radius to 0,alpha to 255.
Mybean bean = new Mybean ();
Bean.radius = 0; Click the rear radius to first set to 0
Bean.alpha = Maxalpha; Alpha set to Maximum value 255
Bean.width = BEAN.RADIUS/8; Stroke width This random
Bean. X = (int) event.getx (); The x-coordinate of the drawn circle
Bean. Y = (int) event.gety (); The y-coordinate of the drawn circle
Bean.paint = Initpaint (Bean.alpha, bean.width);
Break
}
return true;
}
After setting the properties, give handler to draw the interface, each after x milliseconds, draw the radius of the circle +n, transparency-m
Bean.radius + = 5;//radius +5 per time
Bean.alpha-= 10;//transparency minus 10 per time
if (Bean.alpha < 0) {
Transparency is 0 when it rains 0.
Bean.alpha = 0;
}
Bean.width = BEAN.RADIUS/8; Stroke width set to 1/4 of radius
Bean.paint.setAlpha (Bean.alpha);
Bean.paint.setStrokeWidth (Bean.width);
So far, all of our main code has been implemented
Attached demo Address: http://download.csdn.net/detail/qq_18612815/9511652
Android custom Control (effect one) tap the screen to draw the ring based on the location you clicked