实现了类似于iPhone 的列表滑动功能:SwipeMenuListView

jopen 10年前

SwipeMenuListView 实现了类似于iPhone 的列表滑动功能,开发者可以在此基础上制作一些类似滑动删除的效果, 纯代码添加菜单,不需要在item布局文件中添加菜单的布局。

Usage

Step 1

  • add SwipeMenuListView in layout xml
    <com.baoyz.swipemenulistview.SwipeMenuListView          android:id="@+id/listView"          android:layout_width="match_parent"          android:layout_height="match_parent" />

Step 2

  • create a SwipeMenuCreator to add items.
    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
    listView.setOnMenuItemClickListener(new OnMenuItemClickListener() {      @Override      public void onMenuItemClick(int position, SwipeMenu menu, int index) {          switch (index) {          case 0:              // open              break;          case 1:              // delete              break;          }      }  });
实现了类似于iPhone 的列表滑动功能:SwipeMenuListView

项目主页:http://www.open-open.com/lib/view/home/1409558158338