Xamarin.android 在截面回收视图中拖放xamarandroid
是否可以在分段回收视图中使用拖放功能 我在RecyclerView中找到了用于拖放的github链接。但我想让它在分段回收视图中实现 请建议Xamarin.android 在截面回收视图中拖放xamarandroid,xamarin.android,Xamarin.android,是否可以在分段回收视图中使用拖放功能 我在RecyclerView中找到了用于拖放的github链接。但我想让它在分段回收视图中实现 请建议 void OnDragInsideRecyclerView(object sender, DragEventArgs e) { var theEvent = e.Event; var view = (View)theEvent.LocalState; var containerView = (Re
void OnDragInsideRecyclerView(object sender, DragEventArgs e)
{
var theEvent = e.Event;
var view = (View)theEvent.LocalState;
var containerView = (RecyclerView)sender;
_currentContactPosition = containerView.GetChildAdapterPosition(view);
// Ensure the position is valid.
if (_currentContactPosition != -1)
{
_contactToMove = _adapter.MainViewModel.Contacts[_currentContactPosition];
}
switch (theEvent.Action)
{
case DragAction.Location:
View onTopOf = containerView.FindChildViewUnder(theEvent.GetX(), theEvent.GetY());
_newContactPosition = containerView.GetChildAdapterPosition(onTopOf);
// Ensure the new position is valid.
if (_newContactPosition != -1)
{
var layoutManager = (LinearLayoutManager)_recyclerView.GetLayoutManager();
int firstVisiblePosition = layoutManager.FindFirstCompletelyVisibleItemPosition();
int lastVisiblePosition = layoutManager.FindLastVisibleItemPosition();
// Scroll up or down one if we are over the first or last visible list item.
if (_newContactPosition >= lastVisiblePosition)
layoutManager.ScrollToPositionWithOffset(firstVisiblePosition + 1, 0);
else if (_newContactPosition <= firstVisiblePosition)
layoutManager.ScrollToPositionWithOffset(firstVisiblePosition - 1, 0);
// Update the location of the Contact
_adapter.MainViewModel.Contacts.Remove(_contactToMove);
_adapter.MainViewModel.Contacts.Insert(_newContactPosition, _contactToMove);
_adapter.NotifyItemMoved(_currentContactPosition, _newContactPosition);
}
e.Handled = true;
break;
case DragAction.Ended:
// Reset the visibility for the Contact item's view.
// This is done to reset the state in instances where the drag action didn't do anything.
view.Visibility = ViewStates.Visible;
// Boundary condition, scroll to top is moving list item to position 0.
if (_newContactPosition != -1)
{
_recyclerView.ScrollToPosition(_newContactPosition);
_newContactPosition = -1;
}
else
{
_recyclerView.ScrollToPosition(0);
}
e.Handled = true;
break;
}
}
void OnDragInsideRecyclerView(对象发送方,DragEventArgs e)
{
var theEvent=e.事件;
var view=(view)theEvent.LocalState;
var containerView=(RecyclerView)发送方;
_currentContactPosition=containerView.GetChildAdapterPosition(视图);
//确保职位有效。
如果(_currentContactPosition!=-1)
{
_contactToMove=_adapter.MainViewModel.Contacts[_currentContactPosition];
}
开关(事件动作)
{
箱排水。位置:
视图onTopOf=containerView.FindChildViewUnder(theEvent.GetX(),theEvent.GetY());
_newContactPosition=containerView.GetChildAdapterPosition(onTopOf);
//确保新职位有效。
如果(_newContactPosition!=-1)
{
var layoutManager=(LinearLayoutManager)_recyclerView.GetLayoutManager();
int firstVisiblePosition=layoutManager.FindFirstCompletelyVisibleItemPosition();
int lastVisiblePosition=layoutManager.FindLastVisibleItemPosition();
//如果在第一个或最后一个可见列表项上,则向上或向下滚动一个。
如果(\u newContactPosition>=lastVisiblePosition)
layoutManager.ScrollToPositionWithOffset(firstVisiblePosition+1,0);
否则如果(\u newContactPosition添加您的代码尝试。您尝试过吗?我的代码与上面的链接中提到的几乎相似,但我的要求不同。我想在具有节标题的回收器视图之间拖放。您可以用您尝试过的代码详细说明问题吗?您准确地击中了哪里?我添加了此代码,该代码正在运行g对于普通的回收器视图来说很好,但我想在图中所示的分段回收视图中实现这一点。我正在跟踪该链接