gpt4 book ai didi

android - 使用 GestureDetector 调用 Longpress 后调用滚动事件

转载 作者:搜寻专家 更新时间:2023-11-01 09:35:28 24 4
gpt4 key购买 nike

在没有释放屏幕(使用手势检测器)的情况下调用 Longpress 后应该如何调用滚动事件?

这是我的类(class):

public class TestingGestureDetector extends AppCompatActivity implements GestureDetector.OnGestureListener {
TextView mTextView;
private GestureDetector mGestureDetector;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testing_gesture_detector);

mTextView = (TextView) findViewById(R.id.gesture);
mTextView.setOnTouchListener(a());
mGestureDetector = new GestureDetector(this, this); //


}


protected View.OnTouchListener a() {
return new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mGestureDetector.onTouchEvent(event); //

if (event.getAction() == MotionEvent.ACTION_UP)
mTextView.setText("Release");
return true;
}
};
}

@Override
public boolean onDown(MotionEvent event) {
mTextView.setText("Press");
return true;
}

@Override
public void onShowPress(MotionEvent event) {

}

@Override
public boolean onSingleTapUp(MotionEvent event) {
return true;
}

@Override
public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) {

mTextView.setText("Move");
return true;
}

@Override
public void onLongPress(MotionEvent event) {

mTextView.setText("Long Press");
//mGestureDetector.setIsLongpressEnabled(false);
}

@Override
public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {

return true;
}
}

最佳答案

  • 使用 setIsLongpressEnabled(isLongpressEnabled) 禁用长按在你的手势检测器上。
  • 在 0.5 秒后使用定时器或线程。

尝试:

public boolean onTouchEvent(MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)== true)
{
//Fling or other gesture detected (not logpress because it is disabled)
}
else
{
//Manually handle the event.
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
//Remember the time and press position
Log.e("test","Action down");
}
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
//Check if user is actually longpressing, not slow-moving
// if current position differs much then press positon then discard whole thing
// If position change is minimal then after 0.5s that is a longpress. You can now process your other gestures
Log.e("test","Action move");
}
if (event.getAction() == MotionEvent.ACTION_UP)
{
//Get the time and position and check what that was :)
Log.e("test","Action down");
}

}
return true;
}

关于android - 使用 GestureDetector 调用 Longpress 后调用滚动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43614551/

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