Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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_Multi Touch_Ontouchlistener - Fatal编程技术网

拖动和按下按钮-android?

拖动和按下按钮-android?,android,multi-touch,ontouchlistener,Android,Multi Touch,Ontouchlistener,我有几个按钮,我想按下其中一个,然后拖动另一个按钮。您能告诉我应该使用哪个MotionEvent或其他功能吗。我正在使用onTouchListener 有一个图像,你可以看到我想做什么(第一个动作在第一个按钮上向下,拖动第二到第七个按钮,仍然按下屏幕),最后按下每一个白色按钮:![在此处输入图像描述][1] 下面是我的onTouch按钮代码: button1 = (Button) findViewById(R.id.button1); button1.setOnTouchLi

我有几个按钮,我想按下其中一个,然后拖动另一个按钮。您能告诉我应该使用哪个MotionEvent或其他功能吗。我正在使用onTouchListener

有一个图像,你可以看到我想做什么(第一个动作在第一个按钮上向下,拖动第二到第七个按钮,仍然按下屏幕),最后按下每一个白色按钮:![在此处输入图像描述][1]

下面是我的onTouch按钮代码:

button1 = (Button) findViewById(R.id.button1);

    button1.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

                switch (event.getAction())
                {
                    case MotionEvent.ACTION_DOWN:
                        soundIDs[0] = sound.play(R.raw.sample1);
                        button1.setBackgroundResource(R.drawable.white_clicked);
                        break;
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_CANCEL:
                        sound.stop(soundIDs[0]);
                        button1.setBackgroundResource(R.drawable.white);
                        break;
                }
        return false;
        }
    });