源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

详解SwipeListView框架实现微信\QQ滑动删除效果

  • 时间:2020-11-26 23:42 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:详解SwipeListView框架实现微信\QQ滑动删除效果
QQ或者微信出现过滑动,最近联系人列表,可以删去当前选中的联系人,这个功能很棒。 就是试着做了下。其实是使用了开源框架SwipeListView 。  [img]http://files.jb51.net/file_images/article/201608/2016831161452797.gif?201673116159[/img] SwipeListView 与一般的ListView使用方式差不多,只是增加了一些特殊功能。 
<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 -ListView Item正常显示的控件Id,且必须与Item的布局文件中的控件id一样 •swipeBackView - 手指滑动时显示的,隐藏在FrontView后面,且必须与item的布局文件中控件Id一样 •swipeActionLeft - 左滑的动作,默认reveal,即显示BackView,还有dismiss,choice会触发响应的方法。 •swipeActionRight - 右滑动作,其他同上 •swipeMode - Default: 'both' 设置左滑、右滑、都支持 •swipeCloseAllItemsWhenMoveList - 当滚动listview时,关闭所有展开的Item,最好不要设置为false,由于item的    • 复用,false存在一些问题。 •swipeOpenOnLongPress - Default: 'true' 长按时触发显示 •swipeAnimationTime - 动画时间长度 •swipeOffsetLeft - left offset 左偏移量 •swipeOffsetRight - right offset 右偏移量
   mSwipeListView = (SwipeListView) findViewById(R.id.id_swipelistview); 
  mAdapter = new DataAdapter(this, mDatas , mSwipeListView); 
  mSwipeListView.setAdapter(mAdapter); 
 
  mSwipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() 
  { 
   @Override 
   //重写BaseSwipeListViewListener父类需要的方法
   }; 
使用方式很简单 和普通的ListView 相似,不需要多说。  对于 ListView的Item删除单个元素,只需要在Adapter中处理button的点击事件,或者写一个回调传回Activity中处理 我这里给出在Adapter中处理的方式的代码: 
 @Override 
 public View getView(final int position, View convertView, ViewGroup parent) 
 { 
  convertView = mInflater.inflate(R.layout.list_item, null); 
 
  TextView tv = (TextView) convertView.findViewById(R.id.id_text); 
  Button del = (Button) convertView.findViewById(R.id.id_remove); 
  tv.setText(mDatas.get(position)); 
  del.setOnClickListener(new OnClickListener() 
  { 
   @Override 
   public void onClick(View v) 
   { 
    mDatas.remove(position); 
    notifyDataSetChanged(); 
     /** 
     * 关闭SwipeListView 
     * 不关闭的话,刚删除位置的item存在问题 
     * 在监听事件中onListChange中关闭,会出现问题 
     */ 
    mSwipeListView.closeOpenedItems(); 
   } 
  }); 
   
  return convertView; 
 }
源码下载:[url=https://github.com/honjane/SwipeListViewDemo]https://github.com/honjane/SwipeListViewDemo[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部