Import Android.content.Context;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.Paint;
Import android.provider.ContactsContract.CommonDataKinds.Event;
Import Android.util.AttributeSet;
Import android.view.MotionEvent;
Import Android.view.View;
Public class MyView extends View {
Paint paint=new paint ();
private int width;
Private int heigh;
Private float currx=0;
Private float curry=0;
Public MyView (context context) {
Super (context);
}
Public MyView (context context, AttributeSet Attrs) {
Super (context, attrs);
}
Public MyView (context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, defstyle);
}
@Override
protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {
Super.onmeasure (Widthmeasurespec, Heightmeasurespec);
Width=measurespec.getsize (WIDTHMEASURESPEC);
Heigh=measurespec.getsize (HEIGHTMEASURESPEC);
Currx=width/2;
Curry=heigh/2;
}
@Override
protected void OnDraw (canvas canvas) {
Super.ondraw (canvas);
Paint.setcolor (color.red);
Paint.setantialias (TRUE);
Canvas.drawcircle (currx,curry,60, paint);
}
@Override
public boolean ontouchevent (Motionevent event) {
Switch (event.getaction ()) {
Case Motionevent.action_down:
Currx=event.getx ();
Curry=event.gety ();
Postinvalidate ();
Break
Case Motionevent.action_move:
Currx=event.getx ();
Curry=event.gety ();
Postinvalidate ();
Break
Case MOTIONEVENT.ACTION_UP:
Break
Case Motionevent.action_cancel:
Break
}
return true;
}
}
Custom view (small balls move with your finger)