Widget - Drag Widget

img.setOnTouchListener(new OnTouchListener() {

PointF DownPT = new PointF();
PointF StartPT = new PointF();
@Override
public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_MOVE:
PointF mv = new PointF(event.getX() - DownPT.x, event.getY() - DownPT.y);
img.setX((int)(StartPT.x+mv.x));
img.setY((int)(StartPT.y+mv.y));
StartPT = new PointF(img.getX(), img.getY());
break;
case MotionEvent.ACTION_DOWN:
DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF(img.getX(), img.getY());
break;
case MotionEvent.ACTION_UP:
float distance = DownPT.x - event.getX();
if (distance == 0) {
showMessage("Clicked");
}
break;
default : break;
}
return true;
}
});

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Create a Stopwatch App using Chronometer in Sketchware

Create app to save all passwords, protected using voice key