如何停止滑动动画和绘制按钮?

时间:2015-08-18 14:57:44

标签: android canvas android-recyclerview

所以,我有物品的RecyclerView。当用户在左侧滑动项目时,应该在红色背景上显示按钮删除。我通过滑动创建了绘图。但是当我停止刷红色矩形时,就会消失。怎么做这样的方式,刷卡后我看到红色矩形?注意onChildDrawOver()

    ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(
        ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

    public void onChildDrawOver(Canvas canvas, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                            float dX, float dY, int actionState, boolean isCurrentlyActive) {
        LinearLayout linearLayout = (LinearLayout) recyclerView.findViewById(R.id.linearLayout);

            MyAdapter.MyViewHolder vh = (MyAdapter.MyViewHolder) viewHolder;
            vh.mBtn.setVisibility(View.VISIBLE);
            Paint p = new Paint();
            if (dX < 0) {
                p.setARGB(255, 255, 0, 0);
            } else {
                p.setARGB(255, 0, 255, 0);
            }

            canvas.drawRect(linearLayout.getLeft() + dX, linearLayout.getTop() + dY, linearLayout.getRight(), linearLayout.getBottom(), p);
            p.setTextSize(20);
            canvas.drawText("Delete", linearLayout.getLeft(), linearLayout.getTop() / 2, p);
            // super.onChildDraw(canvas, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
        // callback for drag-n-drop, false to skip this feature
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
        adapter.showDeleteBtn((MyAdapter.MyViewHolder)viewHolder);
        list.remove(viewHolder.getAdapterPosition());
        adapter.notifyItemRemoved(viewHolder.getAdapterPosition());
    }
});
swipeToDismissTouchHelper.attachToRecyclerView(recyclerView);

0 个答案:

没有答案