Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawingImageView extends View {
- private PointF point;
- private Paint paint = new Paint();
- Initialization init; //<---------------------
- public DrawingImageView(Context context) {
- super(context);
- init = new Initialization(); <-------------------
- }
- public DrawingImageView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public DrawingImageView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
- @Override
- public boolean onTouchEvent(@NonNull MotionEvent event) {
- float x = event.getX();
- float y = event.getY();
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- point = new PointF(x, y);
- invalidate();
- break;
- case MotionEvent.ACTION_MOVE:
- point.set(x, y);
- invalidate();
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- point = null;
- invalidate();
- break;
- }
- return true;
- }
- @Override
- protected void onDraw(@NonNull Canvas canvas) {
- super.onDraw(canvas);
- if (point != null) {
- canvas.drawCircle(point.x, point.y, 100, paint);
- canvas.drawBitmap(init.b01,10,10,paint);<------------
- }
- }
- }
- public class Initialization extends Activity {
- Bitmap b01;
- public Initialization() {
- Bitmap b05 = BitmapFactory.decodeResource(getResources(), R.raw.t02);
- }
- }
- `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement