简体   繁体   English

如何在android中的列表视图中单击按钮向左滑动行

[英]How to slide row to left on button click in listview in android

I have three button on listview row.我在列表视图行上有三个按钮。 I have to click on the left side red button to slide the row little bit left side and to open the delete button on the right side.我必须单击左侧的红色按钮将行稍微向左滑动并打开右侧的删除按钮。 On that button, by clicking I needed to delete the row.在那个按钮上,通过单击我需要删除该行。 Can any one help me with this functionality?任何人都可以帮助我使用此功能吗? Here I attached the my layout image.在这里我附上了我的布局图片。

这是图像

Follow this:按照这个:

  1. Make one delete button on the right side and set it's visibility to gone in xml file.在右侧创建一个删除按钮并将其可见性设置为在 xml 文件中消失。

  2. When user clicks on the left side red button set delete button's visibility to visible.当用户单击左侧的红色按钮时,将删除按钮的可见性设置为可见。

  3. In the delete button's onClick method add your logic to delete the row.在删除按钮的 onClick 方法中,添加删除行的逻辑。

Code:代码:

<ImageButton
    android:id="@+id/category_delete"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="50dp"
    android:background="#fff"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:src="@drawable/img_delete_category" />


<EditText
    android:id="@+id/added_category_name"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:paddingTop="20dp"
    android:background="#fff"
    android:layout_alignParentRight="@+id/category_delete"
    android:textColor="#000"
    android:paddingLeft="10dp"
    android:fontFamily="Cabin-Regular"
    android:textSize="14dp"
    android:hint="category name"
    android:singleLine="true"
    android:layout_toRightOf="@+id/category_delete"
    android:layout_toEndOf="@+id/category_delete" />



<ImageButton
    android:id="@+id/category_edit"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="50dp"
    android:background="#fff"
    android:layout_toLeftOf="@+id/unlock_image"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:src="@drawable/img_editcategory" />


<ImageButton
    android:id="@+id/unlock_image"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="50dp"
    android:layout_alignParentRight="true"
     android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:background="#fff"
    android:layout_marginBottom="5dp"
    android:src="@drawable/img_unlocked" />
<Button
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:text="Delete"
    android:textColor="#fff"
    android:visibility="visible"
    android:id="@+id/delete_btn"
    android:background="#FF0000"

    />

Here is the nice library for it AndroidSwipeLayout这是它的好库AndroidSwipeLayout

hope this will help you希望能帮到你

This are the library for that这是图书馆

  1. Check out SwipeActionAdapter查看SwipeActionAdapter
  2. Check out SwipeMenuListView查看SwipeMenuListView

Check This answer, too android listview slide left right也检查这个答案android listview slide left right

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM