2016-08-05 110 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