当前位置: 代码迷 >> Android >> Android UI ListView的滑动删除成效之SwipeListView
  详细解决方案

Android UI ListView的滑动删除成效之SwipeListView

热度:38   发布时间:2016-04-28 06:56:46.0
Android UI ListView的滑动删除效果之SwipeListView
SwipeListView是对ListView的扩展,实现滑动显示删除等操作按钮。

https://github.com/47deg/android-swipelistview

***依赖于NineOldAndroids https://github.com/JakeWharton/NineOldAndroids

在layout的布局文件中使用SwipeListView:
<com.fortysevendeg.swipelistview.SwipeListView            xmlns:swipe="http://schemas.android.com/apk/res-auto"            android:id="@+id/example_lv_list"            android:listSelector="#00000000"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            swipe:swipeFrontView="@+id/front"            swipe:swipeBackView="@+id/back"            swipe:swipeActionLeft="[reveal | dismiss]"            swipe:swipeActionRight="[reveal | dismiss]"            swipe:swipeMode="[none | both | right | left]"            swipe:swipeCloseAllItemsWhenMoveList="[true | false]"            swipe:swipeOpenOnLongPress="[true | false]"            swipe:swipeAnimationTime="[miliseconds]"            swipe:swipeOffsetLeft="[dimension]"            swipe:swipeOffsetRight="[dimension]"            />

  • swipeFrontView - Required - front view id.
  • swipeBackView - Required - back view id.
  • swipeActionLeft - Optional - left swipe action Default: 'reveal'
  • swipeActionRight - Optional - right swipe action Default: 'reveal'
  • swipeMode - Gestures to enable or 'none'. Default: 'both'
  • swipeCloseAllItemsWhenMoveList - Close revealed items on list motion. Default: 'true'
  • swipeOpenOnLongPress - Reveal on long press Default: 'true'
  • swipeAnimationTime - item drop animation time. Default: android configuration
  • swipeOffsetLeft - left offset
  • swipeOffsetRight - right offset


swipeFrontView和swipeBackView必须和list_item.xml中设置的布局ID相同。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="60dp"    tools:context=".MainActivity" >    <LinearLayout        android:id="@+id/back"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:background="#ffcccccc"        android:gravity="center|right" >        <Button            android:id="@+id/remove"            style="@style/button_text"            android:layout_width="80dp"            android:layout_height="wrap_content"            android:layout_gravity="center"            android:background="@drawable/red_button"            android:text="Delete" >        </Button>    </LinearLayout>    <LinearLayout        android:id="@+id/front"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:background="#ffffffff" >        <TextView            android:id="@+id/text"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="10dp"            android:textSize="25sp"            android:gravity="center_vertical"            android:minHeight="?android:attr/listPreferredItemHeight"            android:textAppearance="?android:attr/textAppearanceLarge" >        </TextView>    </LinearLayout></FrameLayout>


效果图:


对比微信5的订阅号页面:

  相关解决方案