gpt4 book ai didi

java - 上下滑动半屏调节音量,半屏调节亮度

转载 作者:行者123 更新时间:2023-12-02 01:19:54 25 4
gpt4 key购买 nike

我想读取用户是否在屏幕右侧或左侧滑动。我想在用户在屏幕右侧向上滑动时提高音量,在用户在屏幕左侧滑动时提高亮度。我能够读取向上、向下、向右、向左滑动,但我想读取 swipeUpRight、swipeDownRight 和 swipeUpLeft、swipeDownLeft

private final class GestureListener extends SimpleOnGestureListener {

private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;

@Override
public boolean onDown(MotionEvent e) {
return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
/*Log.e("TAG", "Y: " + e1.getY() + " , " + e2.getY());
Log.e("TAG", "diffY: " + diffY);
Log.e("TAG", "X: " + e1.getX() + " , " + e2.getX());*/
Log.e("TAG", "X: " + Math.abs(diffX));
Log.e("TAG", "Y: " + Math.abs(diffY));
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
result = true;
}
} else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeBottomRight();
} else {
onSwipeTopRight();
}
result = true;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}

最佳答案

您是否尝试过以下方法:

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
int halfWidth = getWindow().getDecorView().getWidth() / 2;
if (e1.getX() < halfWidth) {
//leftSide code
else{
//rightSide code
}
}

关于java - 上下滑动半屏调节音量,半屏调节亮度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57906808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com