gpt4 book ai didi

java - 如何检测屏幕左侧或右侧是否执行了运动事件手势?

转载 作者:行者123 更新时间:2023-11-30 10:35:20 26 4
gpt4 key购买 nike

与 MX 播放器的情况一样,左手垂直滑动手势控制亮度,右手垂直滑动手势控制音量,我需要在我的应用程序中应用相同的概念。那我应该怎么做呢?

最佳答案

你可以像这样监听 onTouchEvent:

public class MainActivity extends Activity {
float x1 = 0;
float y1 = 0;
float x2 ;
float y2 ;
...

@Override
public boolean onTouchEvent(MotionEvent event){
int action = MotionEventCompat.getActionMasked(event);

switch(action) {
case (MotionEvent.ACTION_DOWN) :
x1 = event.getX();
y1 = event.getY();
return true;
case (MotionEvent.ACTION_UP) :
x2 = event.getX();
y2 = event.getY();

//if left to right sweep event on screen
if (x1 < x2)
{
Toast.makeText(this, "Left to Right Swap Performed", Toast.LENGTH_LONG).show();
}

// if right to left sweep event on screen
if (x1 > x2)
{
Toast.makeText(this, "Right to Left Swap Performed", Toast.LENGTH_LONG).show();
}

// if UP to Down sweep event on screen
if (y1 < y2)
{
Toast.makeText(this, "UP to Down Swap Performed", Toast.LENGTH_LONG).show();
}

//if Down to UP sweep event on screen
if (y1 > y2)
{
Toast.makeText(this, "Down to UP Swap Performed", Toast.LENGTH_LONG).show();
}
return true;

关于java - 如何检测屏幕左侧或右侧是否执行了运动事件手势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41242336/

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