我在RecyclerView
内有Fragment
,我想从此Recycler
Adapter
拖动行并将其放入容器Fragment
- 中的视图中同一个片段中的Recycler
和View
,我尝试了很多来自堆栈和youtube的代码,我用这个代码来实现拖放但它只适用于适配器的视图外侧仅
private class ChoiceTouchListener implements View.OnTouchListener {
RowNewsRecylcerHolder holder;
public ChoiceTouchListener(RowNewsRecylcerHolder holder) {
this.holder = holder;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
LinearLayout.LayoutParams lParams = (LinearLayout.LayoutParams) v.getLayoutParams();
_xDelta = X - lParams.leftMargin;
_yDelta = Y - lParams.rightMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) v.getLayoutParams();
layoutParams.leftMargin = X - _xDelta;
layoutParams.topMargin = Y - _yDelta;
layoutParams.rightMargin = 250;
layoutParams.bottomMargin = 250;
v.setLayoutParams(layoutParams);
break;
}
holder.getRowCardViewContent().invalidate();
return true;
}
}