daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Enabled left drag edge in ViewHolder causes strange behavior #269

Closed awhlee closed 8 years ago

awhlee commented 8 years ago

Hi,

If I use the "default" values (right edge drag is enabled) in my xml, everything works fine for the list items in my recyclerview. I can see the top layer as a default and dragging from right to left shows the underlying layer. Perfect. When I add a left drag edge, there is strange behavior. The top layer's text is no longer visible (just white) and it doesn't seem like a draft from left to right does anything. The draft from right to left still shows the underlying layer.

Here is my xml for the recycler view list item.

<?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >

<com.daimajia.swipe.SwipeLayout xmlns:swipe="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    swipe:leftEdgeSwipeOffset="0dp"
    swipe:rightEdgeSwipeOffset="0dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="#FF5534"
        android:gravity="center"
        android:weightSum="10">

        <ImageView
            android:id="@+id/trash"
            android:layout_width="27dp"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:src="@drawable/placeholder_image" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="5"
            android:text="Delete Item?"
            android:textColor="#fff"
            android:textSize="17sp" />

        <Button
            android:id="@+id/delete"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="4"
            android:background="#ffffff"
            android:text="Yes,Delete"
            android:textColor="#FF5534" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/hidden_recycler_view_item_options"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:elevation="5dp"
        android:padding="10dp">

        <TextView
            android:id="@+id/position"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/text_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:tag="Hover"/>
    </LinearLayout>
</com.daimajia.swipe.SwipeLayout>

I enable the left drag edge in my adapter's onCreateViewHolder() for each ViewHolder:

@Override
public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.thread_list_item,
            parent, false);

    SwipeLayout swipeLayout = (SwipeLayout)view.findViewById(R.id.swipe);
    if (swipeLayout != null) {
        swipeLayout.addDrag(SwipeLayout.DragEdge.Left, swipeLayout.findViewById(
                R.id.hidden_recycler_view_item_options));
    }
    SimpleViewHolder returnView = new SimpleViewHolder(view);
    return returnView;
}

Thanks --Tony

awhlee commented 8 years ago

This was definitely some user error. After playing around (using the sample2 xml as reference), I got it working. Here is the "update" XML file that has something working.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >

<com.daimajia.swipe.SwipeLayout
    xmlns:swipe="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:tag="Bottom2"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:gravity="center"
        android:background="#FF5534"
        android:weightSum="10">

        <ImageView
            android:id="@+id/trash"
            android:layout_width="27dp"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:src="@drawable/android_notification" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="5"
            android:text="Delete Item?"
            android:textColor="#fff"
            android:textSize="17sp" />

        <Button
            android:id="@+id/delete"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="4"
            android:background="#ffffff"
            android:text="Yes,Delete"
            android:textColor="#FF5534" />
    </LinearLayout>

    <LinearLayout
        android:tag="Bottom3"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:gravity="center"
        android:background="#0F5534"
        android:weightSum="10">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="5"
            android:text="Delete Item?"
            android:textColor="#fff"
            android:textSize="17sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white" >
        <TextView
            android:id="@+id/position"
            android:background="@android:color/white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/text_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:tag="Hover"/>
    </LinearLayout>
</com.daimajia.swipe.SwipeLayout>

Not too sure how I got it working (I'll have to dig deeper as soon as I post this) but there are 3 things that I played around with.

  1. Added android:tag styles and use those instead of the ids in the call to addDrag()
  2. Changed the order of the hidden layouts so they are above the visible layout (but with android:tag styles)
  3. Played around with the background colors of the layers (I don't think that this did anything).

Thanks and sorry if I misled anyone earlier. --Tony