I had to create a popup window which is a square (400dp height and 400dp width). Now I want to drag it when I tap a button which is positioned on the top left of the popup. I set onTouch()
on the layout which is placed on the popup and this is the code I use in order to drag it:
@Override
public boolean onTouch(View v, MotionEvent event) {
int eventAction = event.getAction();
switch (eventAction) {
case MotionEvent.ACTION_MOVE: // Drag event
xRow = (int) event.getRawX() - rootView.getWidth();
yRow = (int) event.getRawY() - rootView.getHeight();
/* Updates the position of the popup on the screen */
update(xRow, yRow, -1, -1);
break;
}
return true;
}
The problem is that this seems to work only for Nexus 7. On a tablet of 10 inch, it is not working properly. When I drag it on the larger tablet, there is a space between my finger and popup. So I assume that the units of measurement I use are not the right ones. I have tried to use the Metrics but no success.