0

When I try to swipe-to-dismiss an item in the RecyclerView, the item decoration line remains on the screen (it can be seen on the gif animation I provide: http://imgur.com/v1D149C).

So, when I try to swipe out the recyclerView item, an alert dialog shows a message asking if I want to delete the item or not. As long as I click "OK", items remove normally. But if I click "Cancel", something weird happens, and after that whenever I delete any item in the list, some gap with item decoration line remains on the screen and I don't know what to do with it. I hope someone can help or at least say where to look for the solution, because I'm completely messed up.

I've used this RecyclerView Swipe-to-Dosmiss TouchListener: https://github.com/krossovochkin/Android-SwipeToDismiss-RecyclerView/blob/master/app/src/main/java/com/example/android/swipedismiss/SwipeDismissRecyclerViewTouchListener.java

Here is the code that I use in my app: http://pastebin.com/pkiLBRzr The changes are in the private boolean handleTouchEvent(MotionEvent motionEvent) method between 172 and 280 line (in the case MotionEvent.ACTION_UP:).

Also, I use this as an ItemDecoration: https://gist.github.com/polbins/e37206fbc444207c0e92
And here is my MainActivity: http://pastebin.com/AUdLCHjs

Denis Yakovenko
  • 127
  • 2
  • 11
  • could you post your xml layout file? – George Daramouskas Feb 08 '15 at 19:23
  • Sure, here it is: http://pastebin.com/Cf95zv6f – Denis Yakovenko Feb 08 '15 at 19:28
  • Could you comment out the `` line of `Item Decoration Divider XML` and re run the program to see if the line appears at all? – George Daramouskas Feb 08 '15 at 19:36
  • If I comment it out, the divider doesn't appear. But the gap between items is still there when I remove them. This happens only after I cancel the alert dialog. – Denis Yakovenko Feb 08 '15 at 19:39
  • From what I can understand your implementation of `Swipe-to-Dismiss` works correctly. The problem seems to me that the divider is **in** the container that contains the views that are to be swiped out. Maybe if you define a divider **inside** the view that is to be swiped out you can get the visual effect that you wish. – George Daramouskas Feb 08 '15 at 19:46
  • Sorry, I didn't really get it. Could you exlain that again? Well, I've tried to delete the divider, but the problem still remains to be the same. When I swipe the element out, a small gap remains. – Denis Yakovenko Feb 08 '15 at 19:51

1 Answers1

0

From what I can understand your implementation of Swipe-to-Dismiss works correctly. The problem seems to me that the divider is in the container that contains the views that are to be swiped out. Maybe if you define a divider inside the view that is to be swiped out you can get the visual effect that you wish.

For example, in your XML file that you posted there is a shape defined at the end:

`-------------Item Decoration Divider XML---------
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">
    <size
       android:width="1dp"
       android:height="1dp"/>
    <solid android:color="@color/divider" />
</shape>`

that part of your file seems to be the line that stays put when your remove the view, what I am suggesting is that you have a a line drawn within your textviews that you slide away (for example as a propery of them). Have a look at this question.

Try setting for example the android:divider="?android:dividerHorizontal" property of your LinearLayout or style="?android:attr/listSeparatorTextViewStyle" on your textview.

Community
  • 1
  • 1
George Daramouskas
  • 3,720
  • 3
  • 22
  • 51
  • Unfortunately, that didn't do the trick:( Even after the full deletion of the divider from the project, the problem remains. When I delete an item from the list, a gap remains (even without a divider). – Denis Yakovenko Feb 08 '15 at 20:20