A similar effect was done right, I can now write a drag, but it will start to move from its original position when the second drag.
Here is this code, hold PopupWindow the button to move to move the entire PopupWindow achieve, and initialized Gravity.BOTTOM position, for the first time in this position because of the window, so the move is correct, but the second start, click the button to start moving the moment, it will suddenly jump to the beginning position before moving
private void createPopup ()
{
LayoutInflater flater = (LayoutInflater) getSystemService (LAYOUT_INFLATER_SERVICE);
View view = flater.inflate (R.layout.pop, null);
view.findViewById (R.id.button2). setOnTouchListener (new OnTouchListener ()
{
public boolean onTouch (View v, MotionEvent event)
{
int action = event.getAction ();
switch (action)
{
case MotionEvent.ACTION_DOWN:
lastX = (int) event.getRawX ();
lastY = (int) event.getRawY ();
break;
case MotionEvent.ACTION_MOVE:
int dx = (int) event.getRawX () - lastX;
int dy = (int) event.getRawY () - lastY;
popup.update (dx, dy, -1, -1);
break;
}
return true;
}
});
popup = new PopupWindow (view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popup.setFocusable (false);
popup.setTouchable (true);
popup.setOutsideTouchable (true);
/ / Popup.showAsDropDown (findViewById (R.id.ding), 100, 100);
popup.showAtLocation (findViewById (R.id.button1), Gravity.BOTTOM, 0, 0);
/ /
popup.update ();
}
Reply:
Try to put int dx int dy become a member variable. It is a local variable.
Reply:
The two values should be something to do with it, it will get moved when a new value ah
case MotionEvent.ACTION_MOVE:
int dx = (int) event.getRawX () - lastX;
int dy = (int) event.getRawY () - lastY;
popup.update (dx, -dy , -1, -1);
This place should be negative, move or else just upside down, do not know why
Reply:
PopupWindow drag demo right there, zzjhhb@163.com thanks
Reply:
If this problem should be solved, then the debugger. Most appear on popup.update this method, you re-set its position setposition in ontouchend method in.
Reply:
Own reality. .
Reply:
Landlord to solve this problem
No comments:
Post a Comment