这篇文章将会介绍我是如何学习item的左滑监听事件设置的,首先我们先添加依赖:
compile ‘com.baoyz.swipemenulistview:library:1.3.+’
可以看到,我们是借助大神所写的swipemenulistView这个空间来实现我们的左滑事件的。导入之后呢,我们就可以开始我们的项目了。
首先和往常写listView写好我们的布局文件,但是以前所有的listView控件就需要我们使用这一款新的控件代替了。
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.administrator.learnlistviewmenu.MainActivity">
<com.baoyz.swipemenulistview.SwipeMenuListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</com.baoyz.swipemenulistview.SwipeMenuListView>
</RelativeLayout>
接下来是我们的item布局文件:
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/nameTextView"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="40dp" />
<TextView
android:id="@+id/ageTextView"
android:textSize="15sp"
android:layout_width="match_parent"