Currently every time I click on the desired area, it brings me the imageview but very separate from where I click and I can drag it, the problem is that I need to bring it to the location where I click, this It's my code:
bin.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
Random rand = new Random();
dX = view.getX() - event.getRawX();
dY = view.getY() - event.getRawY();
randomElement = figures.get(rand.nextInt(figures.size()));
Log.v("HOLA:",randomElement.toString());
dX = randomElement.getX() - event.getRawX();
dY = randomElement.getY() - event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
randomElement.animate()
.x(event.getRawX() + dX)
.y(event.getRawY() + dY)
.setDuration(0)
.start();
figures.remove(randomElement);
break;
default:
return false;
}
return true;
}
});
What happens in the code, is that when I click the "bin" it brings me a random Imageview of an ArrayList and that is the object that I move, only that in the emulator, it moves very well but when I run it in my cel, it moves super laggeado apart from the problem that when it brings me the imageview brings it very separated from the area where I click, someone knows if I'm doing it right? or what would be the solution?