我正在尝试使用onTouchListener实现音量控制。 我做得很好,但问题是音量仅增加了1步。
例如:总音量为100,步长为10、20、30、40 ..依此类推,它只会增加10 –没关系我多次滑动布局-
但是音量降低非常迅速,轻微的触摸-像香蕉一样变得零-
@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;
}
答案 0 :(得分:0)
我修复了将setStreamVolume更改为AdjustStreamVolume的问题。