public override void OnClick(View widget) { ToastUtils.ShowShortToast("事件触发了 landscapes and nedes"); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_item_touch_use); SetBackBtn(); SetTitle("ItemDrag And Swipe"); _recyclerView = FindViewById <RecyclerView>(Resource.Id.rv_list); _recyclerView.SetLayoutManager(new LinearLayoutManager(this)); _data = GenerateData(50); var paint = new Paint(); paint.AntiAlias = true; paint.TextSize = 20; paint.Color = Color.Black; _adapter = new ItemDragAdapter(_data); _adapter.ItemDragStart += (s, e) => { Log.Debug(Tag, "drag start"); var holder = e.ViewHolder as BaseViewHolder; // holder.SetTextColor(Resource.Id.tv, Color.White); }; _adapter.ItemDragMoving += (s, e) => { Log.Debug(Tag, $"move from: {e.Source.AdapterPosition} to: {e.Target.AdapterPosition}"); }; _adapter.ItemDragEnd += (s, e) => { Log.Debug(Tag, "drag end"); var holder = e.ViewHolder as BaseViewHolder; // holder.SetTextColor(Resource.Id.tv, Color.Black); }; _adapter.ItemSwipeStart += (s, e) => { Log.Debug(Tag, "view swiped start: " + e.Pos); var holder = e.ViewHolder as BaseViewHolder; // holder.SetTextColor(Resource.Id.tv, Color.White); }; _adapter.ClearView += (s, e) => { Log.Debug(Tag, "View reset: " + e.Pos); var holder = e.ViewHolder as BaseViewHolder; // holder.SetTextColor(Resource.Id.tv, Color.Black); }; _adapter.ItemSwiped += (s, e) => { Log.Debug(Tag, "View Swiped: " + e.Pos); }; _adapter.ItemSwipeMoving += (s, e) => { e.Canvas.DrawColor(new Color(ContextCompat.GetColor(this, Resource.Color.color_light_blue))); // e.Canvas.DrawText("Just some text", 0, 40, paint); }; _itemDragAndSwipeCallback = new ItemDragAndSwipeCallback(_adapter); _itemTouchHelper = new ItemTouchHelper(_itemDragAndSwipeCallback); _itemTouchHelper.AttachToRecyclerView(_recyclerView); //_itemDragAndSwipeCallback.SetDragMoveFlags(ItemTouchHelper.Left | ItemTouchHelper.Right | ItemTouchHelper.Up | ItemTouchHelper.Down); _itemDragAndSwipeCallback.SetSwipeMoveFlags(ItemTouchHelper.Start | ItemTouchHelper.End); _adapter.EnableSwipeItem(); _adapter.EnableDragItem(_itemTouchHelper); _recyclerView.SetAdapter(_adapter); _adapter.ItemClick += (s, e) => { ToastUtils.ShowShortToast("点击了" + e.Position); }; }