码迷,mamicode.com
首页 > 移动开发 > 详细

Android: Dragging Popup Window 可移动浮动框

时间:2015-03-03 18:03:07      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!