最近在https://github.com/中使用一个SwipeMenuListView(左滑出菜单)的控件,先上效果图:
感觉还挺好用,这里记录一下使用方法:
public class SwipeMenuListView extends ListView {
//源码省略,请自行到github下载
}
可以看出直接使用这个控件即可,在xml中使用(记得把源码导入):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.baoyz.swipemenulistview.SwipeMenuListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
接下来是在主函数中的使用方法,这里就是在每一条listview中去添加右边的菜单:
mListView = (SwipeMenuListView) findViewById(R.id.listView);
mListView.setAdapter(mAdapter);
initSwipeMenu();
initListener();
重要的方法就是
initSwipeMenu()
和
initLisener()
,如下