user3077582
user3077582

Reputation: 91

canvas controlling by ontouchlistener

I made a two small rectangle by using canvas but i faced a small problem . I don't know how to control the two rectangles by onTouchlistener and move it vertically and horizontally .

any suggestion ?

Upvotes: 3

Views: 372

Answers (1)

Linda Lowela
Linda Lowela

Reputation: 393

You should try something like this:

private final class MyTouchListener implements OnTouchListener {
 public boolean onTouch(View view, MotionEvent motionEvent) {
  if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
    ClipData data = ClipData.newPlainText("", "");
    DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
    view.startDrag(data, shadowBuilder, view, 0);
    view.setVisibility(View.INVISIBLE);
    return true;
  } else {
    return false;
  }
 }
}

Check for more details on this tutorial.

Upvotes: 4

Related Questions