2016-08-05 109 views
0

我在android應用程序上工作,我想在xamarin表單中創建用於滑動ListView項目的Renderer。但我不知道如何刷卡將工作。如果任何機構有任何想法,請與我在這裏分享的是我的代碼: -滑動列表在Xamarin窗體(Android)中查看目錄項目

public class NativeCell : ViewCell 
    { 
    } 

這裏是渲染器的代碼: -

[assembly: ExportRenderer(typeof(ViewCell), typeof(CustomViewCell))] namespace SwipeListItemRenderer.Droid.CustomControls { 
    public class CustomViewCell : ViewCellRenderer 
    { 
     protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, ViewGroup parent, Context context) 
     { 
      var cell= base.GetCellCore(item, convertView, parent, context); 
      cell.GenericMotion += Cell_GenericMotion; 

      return cell; 
     } 

     private void Cell_GenericMotion(object sender, GenericMotionEventArgs e) 
     { 

     } 
    } } 

我建立的ListView ViewCell渲染器,我想從左到右滑動項目,我想要開火手勢事件: -

private void Cell_GenericMotion(object sender, GenericMotionEventArgs e) 
     { 

     } 
+0

[Xamarin Form中的SwipeListView]的可能重複(http://stackoverflow.com/questions/38767659/swipelistview-in-xamarin-form) –

+0

如果您有更多要添加的內容,請更新您現有的問題。 –

回答

0

可能會使用PanGesture進行滑動。

我已經在PCL項目中使用pangesture在swipe事件中創建了swipecomponent。

連接PanGesture事件

PanGestureRecognizer panGesture = new PanGestureRecognizer(); 
panGesture.PanUpdated += PanGesture_PanUpdated; 
GestureRecognizers.Add(panGesture); 

PanGesture_PanUpdated

private void PanGesture_PanUpdated(object sender, PanUpdatedEventArgs e) 
{ 
    try 
    { 
     switch (e.StatusType) 
     { 
      case GestureStatus.Running: 
       { 
        _gestureX = e.TotalX; 
        _gestureY = e.TotalY; 
       } 
       break; 
      case GestureStatus.Completed: 
       { 
        IsSwipe = true; 
        //Debug.WriteLine("{0} {1}", _gestureX, _gestureY); 
        if (Math.Abs(_gestureX) > Math.Abs(_gestureY)) 
        { 
         if (_gestureX > 0) 
         { 
          OnSwipeRight(null); 
         } 
         else 
         { 
          OnSwipeLeft(null); 
         } 
        } 
        else 
        { 
         if (_gestureY > 0) 
         { 
          OnSwipeDown(null); 
         } 
         else 
         { 
          OnSwipeUP(null); 
         } 
        } 
       } 
       break; 
     } 
    } 
    catch (Exception ex) 
    { 
    } 
} 

添加自定義事件

public event EventHandler SwipeUP; 
protected void OnSwipeUP(EventArgs e) 
{ 
    if (SwipeUP != null) 
     SwipeUP(this, e); 
} 

public event EventHandler SwipeDown; 
protected void OnSwipeDown(EventArgs e) 
{ 
    if (SwipeDown != null) 
     SwipeDown(this, e); 
} 

public event EventHandler SwipeRight; 
protected void OnSwipeRight(EventArgs e) 
{ 
    if (SwipeRight != null) 
     SwipeRight(this, e); 
} 

public event EventHandler SwipeLeft; 
protected void OnSwipeLeft(EventArgs e) 
{ 
    if (SwipeLeft != null) 
     SwipeLeft(this, e); 
} 

刷卡樣品與souceCode在github上https://github.com/act70255/ListViewSwipeGesture 順便說一句,請更新xamarin 2.3