从RecyclerView Adapter拖动视图以查看容器Fragment内部

时间:2016-09-22 13:34:33

标签: android android-fragments drag-and-drop android-recyclerview recycler-adapter

我在RecyclerView内有Fragment,我想从此Recycler Adapter拖动行并将其放入容器Fragment - 中的视图中同一个片段中的RecyclerView,我尝试了很多来自堆栈和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;
    }
}

0 个答案:

没有答案