private int InsertOntoView(AViews.View view, DragItem item) { var positionEntered = GetListPositionForView(view); var correctedPosition = positionEntered; // If the view already has a translation, we need to adjust the position // If the view has a positive translation, that means that the current position // is actually one index down then where it started. // If the view has a negative translation, that means it actually moved // up previous now we will need to move it down. if (view.TranslationY > 0) { correctedPosition += 1; } else if (view.TranslationY < 0) { correctedPosition -= 1; } // If the current index of the dragging item is bigger than the target // That means the dragging item is moving up, and the target view should // move down, and vice-versa var translationCoef = item.Index > correctedPosition ? 1 : -1; // We translate the item as much as the height of the drag item (up or down) var translationTarget = view.TranslationY + (translationCoef * item.View.Height); ObjectAnimator anim = ObjectAnimator.OfFloat(view, "TranslationY", view.TranslationY, translationTarget); anim.SetDuration(100); anim.Start(); return(correctedPosition); }
/// <summary> /// Handler for Long Click event from <paramref name="view"/> /// </summary> /// <param name="parent"> /// The parent list view . /// </param> /// <param name="view"> /// The view that triggered the long click event /// </param> /// <param name="position"> /// The position of the view in the list (has to be normalized, includes headers). /// </param> /// <param name="id"> /// The id of the item that triggered the event (must be bigger than 0 under normal circumstances). /// </param> /// <returns> /// The <see cref="bool"/> flag that identifies whether the event is handled. /// </returns> public bool OnItemLongClick(AWidget.AdapterView parent, AViews.View view, int position, long id) { var selectedItem = ((IList)_element.ItemsSource)[(int)id]; DragItem dragItem = new DragItem(NormalizeListPosition(position), view, selectedItem); var data = ClipData.NewPlainText(string.Empty, string.Empty); AViews.View.DragShadowBuilder shadowBuilder = new AViews.View.DragShadowBuilder(view); view.Visibility = ViewStates.Invisible; if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { view.StartDragAndDrop(data, shadowBuilder, dragItem, 0); } else { view.StartDrag(data, shadowBuilder, id, 0); } return(true); }