如何实现侧滑删除安卓recyclerview
展开全部
需要的引用
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'1212
开始敲代码
首先搭建布局
主布局就放了一个RecyclerView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:background="#EEEEEE"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:overScrollMode="never"
/>
</RelativeLayout>12345678910111213141234567891011121314
Item布局
com.mjj.slidingbutton.SlidingButtonView 就是自定义的View,继承水平滚动条
<com.mjj.slidingbutton.SlidingButtonView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/white"
android:layout_marginBottom="1dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/tv_delete"
android:layout_height="match_parent"
android:layout_width="80dp"
android:gravity="center"
android:layout_toRightOf="@+id/layout_content"
android:text="删 除"
android:background="@drawable/btn_click_red_havebackground"
android:textColor="#DDFFFFFF"
/>
<RelativeLayout
android:id="@+id/layout_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:textSize="50dp"
android:textColor="#DD000000"
android:background="@drawable/btn_click_black_havebackground"
/>
</RelativeLayout>
</RelativeLayout>
</com.mjj.slidingbutton.SlidingButtonView>
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'1212
开始敲代码
首先搭建布局
主布局就放了一个RecyclerView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:background="#EEEEEE"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:overScrollMode="never"
/>
</RelativeLayout>12345678910111213141234567891011121314
Item布局
com.mjj.slidingbutton.SlidingButtonView 就是自定义的View,继承水平滚动条
<com.mjj.slidingbutton.SlidingButtonView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/white"
android:layout_marginBottom="1dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/tv_delete"
android:layout_height="match_parent"
android:layout_width="80dp"
android:gravity="center"
android:layout_toRightOf="@+id/layout_content"
android:text="删 除"
android:background="@drawable/btn_click_red_havebackground"
android:textColor="#DDFFFFFF"
/>
<RelativeLayout
android:id="@+id/layout_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:textSize="50dp"
android:textColor="#DD000000"
android:background="@drawable/btn_click_black_havebackground"
/>
</RelativeLayout>
</RelativeLayout>
</com.mjj.slidingbutton.SlidingButtonView>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询