RecyclerView ItemTouchHelper Buttons on Swipe

后端 未结 11 1293
春和景丽
春和景丽 2020-11-27 11:05

I am trying to port some iOS functionality to Android.

I intent to create a table where on swipe to the left shows 2 button: Edit and Delete.

I have

11条回答
  •  甜味超标
    2020-11-27 11:09

    I have a much simpler solution:

    1. Add a button to your row XML, width 0, floating on the right:
    > 
    1. in onChildDraw(), just increase its width by the dX value.

       int position = viewHolder.getAdapterPosition();
       View v = recyclerView.getLayoutManager().findViewByPosition(position);
       Button hidden = v.findViewById(R.id.hidden);
       hidden.setLayoutParams(new LinearLayout.LayoutParams((int)-dX, -1));
      

    Make sure not to call the default super.onChildDraw()

提交回复
热议问题