Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/baoyongzhang/SwipeMenuListView
[DEPRECATED] A swipe menu for ListView.
https://github.com/baoyongzhang/SwipeMenuListView
Last synced: 2 months ago
JSON representation
[DEPRECATED] A swipe menu for ListView.
- Host: GitHub
- URL: https://github.com/baoyongzhang/SwipeMenuListView
- Owner: baoyongzhang
- License: mit
- Created: 2014-08-24T15:40:45.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-09-08T07:08:01.000Z (over 2 years ago)
- Last Synced: 2024-10-10T16:43:28.886Z (3 months ago)
- Language: Java
- Homepage:
- Size: 1.77 MB
- Stars: 3,506
- Watchers: 174
- Forks: 1,260
- Open Issues: 137
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- -awesome-android-ui - SwipeMenuListView
- awesome-android-ui - SwipeMenuListView
- awesome-android-ui - SwipeMenuListView
- awesome-android-ui - https://github.com/baoyongzhang/SwipeMenuListView
- awesome-android-ui - https://github.com/baoyongzhang/SwipeMenuListView
README
SwipeMenuListView
=================
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SwipeMenuListView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/912)
[ ![Download](https://api.bintray.com/packages/baoyongzhang/maven/SwipeMenuListView/images/download.svg) ](https://bintray.com/baoyongzhang/maven/SwipeMenuListView/_latestVersion)A swipe menu for ListView.
# Demo
# Usage
### Add dependency
```groovy
dependencies {
compile 'com.baoyz.swipemenulistview:library:1.3.0'
}
```### Step 1
* add SwipeMenuListView in layout xml
```xml
```
### Step 2
* create a SwipeMenuCreator to add items.
```java
SwipeMenuCreator creator = new SwipeMenuCreator() {@Override
public void create(SwipeMenu menu) {
// create "open" item
SwipeMenuItem openItem = new SwipeMenuItem(
getApplicationContext());
// set item background
openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9,
0xCE)));
// set item width
openItem.setWidth(dp2px(90));
// set item title
openItem.setTitle("Open");
// set item title fontsize
openItem.setTitleSize(18);
// set item title font color
openItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(openItem);// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(
getApplicationContext());
// set item background
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,
0x3F, 0x25)));
// set item width
deleteItem.setWidth(dp2px(90));
// set a icon
deleteItem.setIcon(R.drawable.ic_delete);
// add to menu
menu.addMenuItem(deleteItem);
}
};// set creator
listView.setMenuCreator(creator);
```### Step 3
* listener item click event
```java
listView.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
switch (index) {
case 0:
// open
break;
case 1:
// delete
break;
}
// false : close the menu; true : not close the menu
return false;
}
});
```### Swipe directions
```java
// Right
mListView.setSwipeDirection(SwipeMenuListView.DIRECTION_RIGHT);
// Left
mListView.setSwipeDirection(SwipeMenuListView.DIRECTION_LEFT);
```### Create Different Menu
* Use the ViewType of adapter
```java
class AppAdapter extends BaseAdapter {...
@Override
public int getViewTypeCount() {
// menu type count
return 2;
}
@Override
public int getItemViewType(int position) {
// current menu type
return type;
}...
}
```* Create different menus depending on the view type
```java
SwipeMenuCreator creator = new SwipeMenuCreator() {@Override
public void create(SwipeMenu menu) {
// Create different menus depending on the view type
switch (menu.getViewType()) {
case 0:
// create menu of type 0
break;
case 1:
// create menu of type 1
break;
...
}
}};
```* Demo
### Other
* OnSwipeListener
```java
listView.setOnSwipeListener(new OnSwipeListener() {
@Override
public void onSwipeStart(int position) {
// swipe start
}
@Override
public void onSwipeEnd(int position) {
// swipe end
}
});
```* open menu method for SwipeMenuListView
```java
listView.smoothOpenMenu(position);
```* Open/Close Animation Interpolator
```java
// Close Interpolator
listView.setCloseInterpolator(new BounceInterpolator());
// Open Interpolator
listView.setOpenInterpolator(...);
```