Android Custom view need to rewrite OnDraw () and other methods, this blog to everyone to say that the custom view, we need to inherit the view, and then rewrite some
method, a lot of methods, see what you need
Start by writing a custom view inheritance 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);p aint.setcolor (color.red); Canvas.drawcircle (e_x, e_y, N, 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:
<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 " android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin " android:paddingright=" @dimen/activity_horizontal_margin " android:paddingtop=" @dimen /activity_vertical_margin " tools:context=". Mainactivity "> <com.example.engineerjspview.engineerjspview android:layout_width=" match_parent " android:layout_height=" match_parent " android:layout_alignparentbottom=" true " android:layout_ Centerhorizontal= "true"/></relativelayout>
Main activities:
Package com.example.engineerjspview;/** * Custom Engineerjspview * @author engineer-jsp * @date 2014.10.28 * */import and Roid.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:
Customizing the view depends on your needs, not just drawing graphics, I'm just explaining the way to customize the view to rewrite
Android Custom view requires rewriting OnDraw () and other methods