Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT:</p> <p>You indeed need to use <a href="http://developer.android.com/reference/android/graphics/Path.html" rel="nofollow">Path</a> class in android. Sorry I couldn't come up with a code snippet. But here's something to get you started off.</p> <p>When you draw a line - <code>canvas.drawLine(x1, y1, x2, y2, paint);</code> your starting point is <code>(x1,y1)</code>. now, if you need to pull the line from any end, you need to first fix the other end. Say you pull from <code>(x2,y2)</code> . So <code>(x1,y1)</code> becomes constant and you pull from the other end. When using the Path class, first call a <code>moveTo()</code> to this fix point. What it does is it gives a point about which the line has to be moved. Then, you can use the <code>lineTo()</code> call on the touch events to stretch the line accordingly. A lot of tweaking will be needed. But this is what can get you started. Sorry I couldn't come up with a snippet, little short on time. See the documentation of the Path class. You might find some more helpful things.</p> <hr> <p>EDIT:</p> <p>About adding touch listeners to points:</p> <p>Suppose you have a line from <code>(x1,y1)</code> to <code>(x2,y2)</code>.</p> <p>Now to get touch listener for a point, you can add an onTouchListener to your whole view.</p> <pre><code>final View touchView = findViewById(R.id.touchView); touchView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if(event.getX() == x2 &amp;&amp; event.getY() == y2) { //you know that you have clicked on the rear end of the line,so now you can do your dragging stuff. if(event.getAction() == MotionEvent.ACTION_DOWN){ //you know user has clicked in order to draw //redraw the existing line with black color to remove it paint.setColor(Color.BLACK); canvas.drawLine(x1, y1, x2, y2, paint); //reset the paint object paint.setColor(Color.WHITE); //now use moveTo() and lineTo() to attain the functionality of dragging on your Path object path.moveTo(x1,y1); path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_MOVE){ path.lineTo(event.getX(),event.getY()); }else if(event.getAction() == MotionEvent.ACTION_UP){ } } return true; } }); </code></pre> <p>This is just an idea, I still didn't get the opportunity to test it. I hope it helps.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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