private int InsertOntoView(Android.Views.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); }
public bool OnItemLongClick(AdapterView parent, Android.Views.View view, int position, long id) { var selectedItem = ((IList)_element.ItemsSource)[(int)id]; // Creating drag state DragItem dragItem = new DragItem(NormalizeListPosition(position), view, selectedItem); // Creating a blank clip data object (we won't depend on this) var data = ClipData.NewPlainText(string.Empty, string.Empty); // Creating the default drag shadow for the item (the translucent version of the view) // NOTE: Can create a custom view in order to change the dragged item view Android.Views.View.DragShadowBuilder shadowBuilder = new Android.Views.View.DragShadowBuilder(view); // Setting the original view cell to be invisible view.Visibility = ViewStates.Invisible; // NOTE: this method is introduced in Android 24, for earlier versions the StartDrag method should be used view.StartDragAndDrop(data, shadowBuilder, dragItem, 0); return(true); }