Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:按钮跟随光标_Android_Button - Fatal编程技术网

Android 安卓:按钮跟随光标

Android 安卓:按钮跟随光标,android,button,Android,Button,如何在光标移动时更改按钮的位置。 我的意思是如何在我移动按钮时让按钮跟随光标。尝试实现触控监听器。卡拉宾:这是对的:'codemSwitchBtn=Buttoninflater.inflateR.layout.status\u bar,null.findviewbydr.id.lock\u开关\u button;mSwitchBtn.setOnTouchListenernew View.OnTouchListener{private int x;private int y;public bool

如何在光标移动时更改按钮的位置。
我的意思是如何在我移动按钮时让按钮跟随光标。

尝试实现触控监听器。卡拉宾:这是对的:'codemSwitchBtn=Buttoninflater.inflateR.layout.status\u bar,null.findviewbydr.id.lock\u开关\u button;mSwitchBtn.setOnTouchListenernew View.OnTouchListener{private int x;private int y;public boolean onTouchView v,MotionEvent事件{switchevent.getAction{case MotionEvent.ACTION_DOWN:x=intevent.getX;y=intevent.getY;break;case MotionEvent.ACTION_MOVE:mSwitchBtn.layoutx,y,mSwitchBtn.getWidth+x,mSwitchBtn.getHeight+y;mSwitchBtn.invalidate;}返回真;};code'@这似乎是对的,但我不确定mSwitchBtn.getHeight和mSwitchBtn.getWidth方法-它可以返回0。您可以使用`作为一行代码,使用\发布预格式化文本 new View.OnTouchListener() { private float downX = 0; private float downY = 0;

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                case (MotionEvent.ACTION_DOWN):
                    this.downX = motionEvent.getX();
                    this.downY = motionEvent.getY();
                    break;


                case MotionEvent.ACTION_MOVE:
                    final View btn= layout.findViewById(R.id.button);
                    currentView.layout(newLeft,
                            newTop, newRight,
                            newBottom));
                    break;
            }
            return true;
        }
    }