2011-08-04 5 views
0

제스처로 놀고 싶지만 작동시키지 못합니다.MonoDroid 제스처가 작동하지 않습니다.

나는이

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

using Android.App; 
using Android.Content; 
using Android.OS; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 

namespace Myapp 
{ 
    [Activity(Label = "My Activity")] 
    public class AboutActivity : Activity 
    { 
     private TextView displayText; 
     private GestureDetector gestureScanner; 
     private GestureListener gestureListener; 

     protected override void OnCreate(Bundle bundle) 
     { 
      RequestWindowFeature(WindowFeatures.NoTitle); 
      base.OnCreate(bundle); 
      SetContentView(Resource.Layout.About); 


      displayText = FindViewById<TextView>(Resource.Id.Privacy); 

      gestureListener = new GestureListener(displayText); 
      gestureScanner = new GestureDetector(this, gestureListener); 
     } 


     public override bool OnTouchEvent(MotionEvent e) 
     { 
      return gestureScanner.OnTouchEvent(e); 


     } 
    } 

    public class GestureListener : GestureDetector.SimpleOnGestureListener 
    { 
     private readonly TextView view; 
     private static int SWIPE_MAX_OFF_PATH = 250; 
     private static int SWIPE_MIN_DISTANCE = 120; 
     private static int SWIPE_THRESHOLD_VELOCITY = 200; 

     public GestureListener(TextView view) 
     { 
      this.view = view; 
     } 

     public IntPtr Handle 
     { 
      get { throw new NotImplementedException(); } 
     } 

     public bool OnDown(MotionEvent e) 
     { 
      view.Text = "- DOWN -"; 
      return true; 
     } 

     public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) 
     { 
      try 
      { 
       if (Math.Abs(e1.GetY() - e2.GetY()) > SWIPE_MAX_OFF_PATH) 
        return false; 
       // right to left swipe 
       if (e1.GetX() - e2.GetX() > SWIPE_MIN_DISTANCE && Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) 
        Toast.MakeText(view.Context, "Left Swipe", ToastLength.Short).Show(); 
       else if (e2.GetX() - e1.GetX() > SWIPE_MIN_DISTANCE && Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) 
        Toast.MakeText(view.Context, "Right Swipe", ToastLength.Short).Show(); 
      } 
      catch (Exception e) 
      { 
       // nothing 
      } 
      return false; 
     } 

     public void OnLongPress(MotionEvent e) 
     { 
      view.Text = "- LONG PRESS -"; 
     } 

     public bool OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) 
     { 
      view.Text = "- FLING -"; 
      return true; 
     } 

     public void OnShowPress(MotionEvent e) 
     { 
      view.Text = "- SHOW PRESS -"; 
     } 

     public bool OnSingleTapUp(MotionEvent e) 
     { 
      view.Text = "- SINGLE TAP UP -"; 
      return true; 
     } 
    } 

} 

아무것도마다 트리거가 없습니다.

답변

1

게다가 당신은 예를 들어, GestureDetector에 제스처 이벤트를 할당 놓칠 수GestureDetector를 만들 :

gestureDetector.SetOnDoubleTapListener (이);

"여기"는 OnDoubleTapEvent이 위의 줄과 동일한 클래스에 구현됨을 의미합니다.

+0

모든 제스처를 사용하는 레이아웃을 래핑하는 scrollview가 있었기 때문에 왜 작동하지 않는지 알았습니다. 그래서 지금이 문제를 해결하려고 노력하고 있습니다. 이 SetOnDoubleTapListener는 어디에서 구현하겠습니까? 동일한 파일의 다른 메서드일까요? – chobo2

+0

예, 동일한 클래스에서 구현할 수 있습니다. 귀하의 코드에 따르면 대신 GestureListener 클래스에서 구현할 수 있습니다. –

관련 문제