Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.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/3/android/195.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
C#Android:如何检测单个视图的滑动手势,如按钮、文本视图、整个活动等_C#_Android_Xamarin_Touch_Gesture - Fatal编程技术网

C#Android:如何检测单个视图的滑动手势,如按钮、文本视图、整个活动等

C#Android:如何检测单个视图的滑动手势,如按钮、文本视图、整个活动等,c#,android,xamarin,touch,gesture,C#,Android,Xamarin,Touch,Gesture,我正在尝试开发一个应用程序,其中将有3-4个按钮。在每个按钮上,我都要检测向右/向左/向上/向下滑动的手势。但是我想要功能 对于每个按钮,这些手势的类型都不同。我不明白怎么做。请有人帮忙。目前,我能够成功地检测到刷卡 整个布局/类上的手势,但无法对特定视图(如按钮、文本视图等)执行此操作 public class MainActivity extends Activity implements GestureDetector.OnGestureListener, GestureD

我正在尝试开发一个应用程序,其中将有3-4个按钮。在每个按钮上,我都要检测向右/向左/向上/向下滑动的手势。但是我想要功能 对于每个按钮,这些手势的类型都不同。我不明白怎么做。请有人帮忙。目前,我能够成功地检测到刷卡 整个布局/类上的手势,但无法对特定视图(如按钮、文本视图等)执行此操作

public class MainActivity extends Activity implements
    GestureDetector.OnGestureListener,
    GestureDetector.OnDoubleTapListener{

private static final String DEBUG_TAG = "Gestures";
private GestureDetectorCompat mDetector;

// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Instantiate the gesture detector with the
    // application context and an implementation of
    // GestureDetector.OnGestureListener
    mDetector = new GestureDetectorCompat(this,this);
    // Set the gesture detector as the double tap
    // listener.
    mDetector.setOnDoubleTapListener(this);
}

@Override
public boolean onTouchEvent(MotionEvent event){
    this.mDetector.onTouchEvent(event);
    // Be sure to call the superclass implementation
    return super.onTouchEvent(event);
}

@Override
public boolean onDown(MotionEvent event) {
    Log.d(DEBUG_TAG,"onDown: " + event.toString());
    return true;
}

@Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
        float velocityX, float velocityY) {
    Log.d(DEBUG_TAG, "onFling: " + event1.toString()+event2.toString());
    return true;
}

@Override
public void onLongPress(MotionEvent event) {
    Log.d(DEBUG_TAG, "onLongPress: " + event.toString());
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
        float distanceY) {
    Log.d(DEBUG_TAG, "onScroll: " + e1.toString()+e2.toString());
    return true;
}

@Override
public void onShowPress(MotionEvent event) {
    Log.d(DEBUG_TAG, "onShowPress: " + event.toString());
}

@Override
public boolean onSingleTapUp(MotionEvent event) {
    Log.d(DEBUG_TAG, "onSingleTapUp: " + event.toString());
    return true;
}

@Override
public boolean onDoubleTap(MotionEvent event) {
    Log.d(DEBUG_TAG, "onDoubleTap: " + event.toString());
    return true;
}

@Override
public boolean onDoubleTapEvent(MotionEvent event) {
    Log.d(DEBUG_TAG, "onDoubleTapEvent: " + event.toString());
    return true;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent event) {
    Log.d(DEBUG_TAG, "onSingleTapConfirmed: " + event.toString());
    return true;
}

}

Hi Rahul,实际上这是java代码,我已经试过了,但在C#中的实现有些不同。因此,我正在寻找C#(xamarin)中的示例,它应该会有帮助。