SwipeListView 详解 实现微信 QQ等滑动删除效果
2016-08-20 15:16
826 查看
QQ或者微信出现过滑动,最近联系人列表,可以删去当前选中的联系人,这个功能玩起来很爽 ,
就是试着做了下。其实是使用了开源框架SwipeListView 。
******************SwipeListView 与一般的ListView使用方式差不多,只是增加了一些特殊功能。
[html] view
plain copy
<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]"
/>
复用,false存在一些问题。
[html] view
plain copy
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中处理的方式的代码:
[html] view
plain copy
@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;
}
源码下载 点击这里---------------------------------------------------------------------------------------------
就是试着做了下。其实是使用了开源框架SwipeListView 。
******************SwipeListView 与一般的ListView使用方式差不多,只是增加了一些特殊功能。
[html] view
plain copy
<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 右偏移量
[html] view
plain copy
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中处理的方式的代码:
[html] view
plain copy
@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;
}
源码下载 点击这里---------------------------------------------------------------------------------------------
相关文章推荐
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- (4.2.5) 【android开源组件】SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- 详解SwipeListView框架实现微信\QQ滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- Android listview 侧滑 SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 详解 实现微信,QQ等滑动删除效果
- SwipeListView 具体解释 实现微信,QQ等滑动删除效果
- SwipeListView 具体解释 实现微信,QQ等滑动删除效果
- SwipeListView 详细介绍(实现微信,QQ等滑动删除效果)
- Android SwipeListView 实现ListView的滑动删除效果
- Android实战简易教程<十四>(介绍SwipeMenuListView-简单实现类似QQ的滑动删除效果)