标签:
final View cv = new View(this); setContentView(cv); TextView tv = new TextView(this); tv.setBackgroundColor(0xffeeeeee); tv.setTextColor(0xff000000); tv.setTextSize(24); tv.setText("click me\nthen drag me"); tv.setPadding(8, 8, 8, 8); mPopup = new PopupWindow(tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
OnTouchListener otl = new OnTouchListener() { private float mDx; private float mDy; @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN) { mDx = mCurrentX - event.getRawX(); mDy = mCurrentY - event.getRawY(); } else if (action == MotionEvent.ACTION_MOVE) { mCurrentX = (int) (event.getRawX() + mDx); mCurrentY = (int) (event.getRawY() + mDy); mPopup.update(mCurrentX, mCurrentY, -1, -1); } return true; } }; tv.setOnTouchListener(otl); mCurrentX = 20; mCurrentY = 50; cv.post(new Runnable() { @Override public void run() { mPopup.showAtLocation(cv, Gravity.NO_GRAVITY, mCurrentX, mCurrentY); } });
Android: Dragging Popup Window 可移动浮动框
标签:
原文地址:http://www.cnblogs.com/welhzh/p/4311383.html