Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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_Ontouchlistener - Fatal编程技术网

Android 手势音量控制

Android 手势音量控制,android,ontouchlistener,Android,Ontouchlistener,我正在尝试使用onTouchListener实现音量控制。 我做得很好,但问题是音量只增加了一步 例如:总体积为100,步长为10,20,30,40。。如此类推,它只会增加10次——不管我刷布局多少次-- 但是音量下降是超瞬间的,轻微的触碰——像香蕉一样变为零-- @覆盖 公共布尔onTouch(视图v,运动事件){ 如果(event.getAction()==MotionEvent.ACTION_向下| | event.getAction()==MotionEvent.ACTION_向上) L

我正在尝试使用onTouchListener实现音量控制。 我做得很好,但问题是音量只增加了一步

例如:总体积为100,步长为10,20,30,40。。如此类推,它只会增加10次——不管我刷布局多少次--

但是音量下降是超瞬间的,轻微的触碰——像香蕉一样变为零--

@覆盖
公共布尔onTouch(视图v,运动事件){
如果(event.getAction()==MotionEvent.ACTION_向下| | event.getAction()==MotionEvent.ACTION_向上)
Log.i(标记“Action:+event.getAction()+”\t X:+event.getRawX()+“\t Y:+event.getRawY());
开关(event.getAction()){
case MotionEvent.ACTION\u DOWN:
downY=event.getY();
case MotionEvent.ACTION\u UP:
downY=event.getY();
case MotionEvent.ACTION\u移动:
float y2=event.getY();
diffY=(long)(Math.ceil(event.getY()-downY));
//if(Math.abs(diffY)>Math.abs(diffX)){
if(绒毛状y2){
//向上滑动音量增加
//audioManager.adjustVolume(audioManager.ADJUST\u RAISE,audioManager.FLAG\u PLAY\u SOUND);
audioManager.setStreamVolume(audioManager.STREAM\u MUSIC、audioManager.ADJUST\u RAISE、audioManager.FLAG\u PLAY\u SOUND);
}
//  }
}
返回true;
}

我将setStreamVolume更改为adjustStreamVolume,将其修复

用seekbar来代替它,如果你不介意的话,还有一个垂直的seekbar。我想了一下,但是在其他应用程序上使用了覆盖层,效果不太好
@Override
public boolean onTouch(View v, MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_UP)
        Log.i(TAG, "Action :" + event.getAction() + "\t X :" + event.getRawX() + "\t Y :"+ event.getRawY());

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:


            downY = event.getY();

        case MotionEvent.ACTION_UP:

            downY = event.getY();

        case MotionEvent.ACTION_MOVE:


            float y2 = event.getY();

            diffY = (long) (Math.ceil(event.getY() - downY));

            //if (Math.abs(diffY) > Math.abs(diffX)) {

                if (downY < y2) {

                    //down swipe volume decrease
           //         audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND);
                    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND);
                } else if (downY > y2) {

                    //up  swipe volume increase
              //      audioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND);
                    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND);
                }
          //  }
       }

    return true;

}