Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Implement onTouchListener on path objects
    primarykey
    data
    text
    <p>I have created a path objects as shown below which draws a different shapes.Different buttons response to drawing different shapes on the canvas. I would like to shift the path objects that i have created in the canvas but I do not know how to.</p> <p>I only know the method of implementing ontouchlistener on a bitmap and not on path objects.</p> <p>my codes are as follows:</p> <pre><code>ArrayList&lt;Path&gt; paths = new ArrayList&lt;Path&gt;(); @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); paintColor.setColor(Color.RED); paintColor.setStrokeWidth(2); paintColor.setStyle(Paint.Style.STROKE); if (MainActivity.isRectangle) { Path path = new Path(); path.moveTo(1, 1); path.lineTo(90, 1); path.lineTo(90, 60); path.lineTo(1, 60); path.close(); paths.add(path); } for (Path p : paths) { canvas.drawPath(p, paintColor ); } canvas.drawPath(path, paintColor); invalidate(); } //mainActivity rectbutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub isTriangle = false; isRectangle = true; isCircle= false; isParallelogram = false; isTapezium = false; dv.invalidate(); }// onclick }); </code></pre> <p>onTouchEvent</p> <pre><code>@Override public boolean onTouch(View v,MotionEvent event){ switch(event.getAction()){ case MotionEvent.ACTION_DOWN: //screen touch get x of the touch event x = event.getX(); //screen touch get y of the touch event y =event.getY(); for (Path p : paths) { path.moveTo(x,y); } dv.invalidate(); break; case MotionEvent.ACTION_UP: //screen touch get x of the touch event x = event.getX(); //screen touch get y of the touch event y =event.getY(); break; case MotionEvent.ACTION_MOVE: //screen touch get x of the touch event x = event.getX(); //screen touch get y of the touch event y =event.getY(); break; } return true; } </code></pre> <p>Please advice. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload