following code to achieve this is PopupWindow press the button , move the movement can be achieved throughout the PopupWindow , initialized to Gravity.BOTTOM position for the first time since the window at this location , so the move is correct, but the second started , click the button to start moving the moment , it will suddenly jump to the starting position , then move
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();
}
------ Solution ------------------------------------- -------
try to put int dx int dy become a member variable. It is a local variable .
------ Solution ------------------------------------ --------
debug this problem if it should be solved. Most appear in popup.update this method , you re in ontouchend method in setting its location setposition.
------ reference --------------------------------------- < br> 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 , or move up and down just reversed, do not know why
------ reference -------------------- -------------------
PopupWindow drag a demo do , zzjhhb@163.com thanks
------ reference --- ------------------------------------
own reality. .
没有评论:
发表评论