daimajia / AndroidSwipeLayout

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

Swipe Left?? #158

Open GithubBell opened 9 years ago

GithubBell commented 9 years ago

Hi,this is concerning the List View Swipe code your library allows to Implement.

There is a right to left swipe view that shows the delete Item menu,but how do we create a layout that will allow us to Implement a swipe from left to right to show something on the other side too?

kostas-matsoukas commented 9 years ago

This is a really old question, but you can use this:

swipeLayout.addDrag(SwipeLayout.DragEdge.Left, findViewById(R.id.left);
swipeLayout.addDrag(SwipeLayout.DragEdge.Right, findViewById(R.id.right);

This way, when you swipe left you will show the left view, and when you swipe right you will show the right view.

frodberserk commented 8 years ago

If I add only right view, it shows me only on right swipe. But if I add only left view, it shows me in both left and right swipe. Any ideas?

Code:

        swipeLayout = (SwipeLayout) itemView;
        swipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
        swipeLayout.addDrag(SwipeLayout.DragEdge.Left, swipeLeftView);

In case you need xml:

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

<!--Left drawer-->
<FrameLayout
    android:id="@+id/bottom_wrapper_left"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:paddingRight="12dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:drawableTop="@drawable/ic_add_button"
        android:gravity="center"
        android:padding="16dp"
        android:text="@string/connect_label"
        android:textColor="#81B3F6"
        android:textSize="16sp" />
</FrameLayout>

<!--&lt;!&ndash;Right drawer&ndash;&gt;-->
<!--<FrameLayout-->
<!--android:id="@+id/bottom_wrapper_right"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="match_parent"-->
<!--android:paddingLeft="12dp">-->

<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center"-->
<!--android:drawableTop="@drawable/ic_trash_button"-->
<!--android:gravity="center"-->
<!--android:padding="16dp"-->
<!--android:text="@string/block_label"-->
<!--android:textColor="#D80302"-->
<!--android:textSize="16sp" />-->
<!--</FrameLayout>-->

<!--Row of recycler view-->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="12dp"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="12dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/appBackground"
            android:padding="16dp">

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/ivProfilePic"
                android:layout_width="@dimen/profile_pic_side"
                android:layout_height="@dimen/profile_pic_side"
                android:background="@drawable/btn_black_rectangle" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@id/ivProfilePic"
                android:layout_alignTop="@id/ivProfilePic"
                android:layout_marginLeft="16dp"
                android:layout_toRightOf="@id/ivProfilePic"
                android:gravity="center_vertical">

                <TextView
                    android:id="@+id/tvName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_toLeftOf="@+id/tvYou"
                    android:fontFamily="sans-serif-medium"
                    android:textColor="@android:color/black"
                    android:textSize="18sp" />

                <TextView
                    android:id="@+id/tvJob"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/tvName"
                    android:layout_marginBottom="4dp"
                    android:layout_marginTop="4dp"
                    android:fontFamily="sans-serif-light"
                    android:maxLines="2"
                    android:textColor="@android:color/black"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/tvLocation"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/tvJob"
                    android:textColor="@android:color/black"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/tvYou"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:background="@drawable/btn_green_filled_round_rectangle"
                    android:fontFamily="sans-serif-light"
                    android:paddingBottom="1dp"
                    android:paddingLeft="8dp"
                    android:paddingRight="8dp"
                    android:paddingTop="1dp"
                    android:text="@string/label_here"
                    android:textColor="@color/appBackground"
                    android:textSize="12sp" />

            </RelativeLayout>

            <TextView
                android:id="@+id/tvViewLinkedinProfile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/ivProfilePic"
                android:layout_gravity="center"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="8dp"
                android:layout_toRightOf="@id/ivProfilePic"
                android:background="@drawable/btn_black_rectangle"
                android:fontFamily="sans-serif-light"
                android:gravity="center"
                android:padding="8dp"
                android:text="@string/view_linkedin_profile"
                android:textColor="@android:color/black" />
        </RelativeLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

</com.daimajia.swipe.SwipeLayout>

kostas-matsoukas commented 8 years ago

@frodberserk , I think this will work for you when you want only left swipe:

swipeLayout.setLeftSwipeEnabled(true);
swipeLayout.setRightSwipeEnabled(false);
ganpatgithub commented 7 years ago

when I try this ((MyViewHolder) holder).swipeLayout.addDrag(SwipeLayout.DragEdge.Left, ((MyViewHolder) holder).ll_SwipeDown); it gives me this error Error:(149, 48) error: cannot find symbol method addDrag(DragEdge,LinearLayout) why this error is comming please sove thanks in advance

EonKid commented 6 years ago

@ganpatgithub You should manually add the classes of this SwipeLayout library using sample code provided by @HarshEvilGeek .I have successfully implemented this library in RecycleView. https://github.com/HarshEvilGeek/AndroidSwipeLayout/tree/master/demo