Android custom View needs to override ondraw () and other methods
Android custom View Requires override of ondraw () and other methods. This blog tells you how to write a custom View. We need to inherit the View and then rewrite some
There are many methods, depending on what method you need
First, write a custom View to inherit the View.
Package com. example. engineerjspview; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. util. attributeSet; import android. view. motionEvent;/*** custom EngineerJspView * @ author Engineer-Jsp * @ date 2014.10.28 **/import android. view. view; public class EngineerJspView extends View {public float E_X = 188; public float E_Y = 188; Paint paint = new Paint (); public EngineerJspView (Context context) {super (context);} public EngineerJspView (Context context, AttributeSet set) {super (context, set) ;}@ Overrideprotected void onDraw (Canvas canvas) {super. onDraw (canvas); paint. setColor (Color. RED); canvas. drawCircle (E_X, E_Y, 88, paint);} @ Overridepublic boolean onTouchEvent (MotionEvent event) {E_X = event. getX (); E_X = event. getY (); invalidate (); return false ;}@ Overrideprotected void onAnimationStart () {super. onAnimationStart () ;}@ Overrideprotected void onAnimationEnd () {super. onAnimationEnd ();}}
Layout file:
Main activity:
Package com. example. engineerjspview;/*** custom EngineerJspView * @ author Engineer-Jsp * @ date 2014.10.28 **/import android. OS. bundle; import android. app. activity; import android. view. menu; import android. view. view; public class MainActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main );}}
Effect:
Custom View depends on your needs. It is not just about drawing a picture. Here I just want to explain how to rewrite the custom View ~~