SwipeListView 详解 实现微信,QQ等滑动删除效果
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/28508769
今天看别人项目,看到别人使用了SwipeListView,Google一把,果然github上的,也参考了csdn上的几篇文章,然后自己写了个例子,分享给大家。
效果图:
嗯,看一眼SwipeListView的参数的设置:
If you decide to use SwipeListView as a view, you can define it in your xml layout like this:
<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. 即ListView Item正常显示的控件Id,且必须与Item的布局文件中的控件id一样swipeBackView- Required -
back view id. 手指滑动时显示的,隐藏在FrontView后面,且必须与item的布局文件中控件Id一样swipeActionLeft- Optional - left swipe action Default:
'reveal' 左滑的动作,默认reveal,即显示BackView,还有dismiss,choice会触发响应的方法。swipeActionRight- Optional - right swipe action
Default: 'reveal' 同上swipeMode- Gestures to enable or 'none'. Default:
'both' 设置左滑、右滑、都支持swipeCloseAllItemsWhenMoveList- Close revealed
items on list motion. Default: 'true' 当滚动listview时,关闭所有展开的Item,最好不要设置为false,由于item的复用,false存在一些问题。swipeOpenOnLongPress- Reveal on long press Default:
'true' 长按时触发显示swipeAnimationTime- item drop animation time. Default:
android configuration 动画时间长度swipeOffsetLeft- left offset 左偏移量swipeOffsetRight- right offset 右偏移量
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clickable="true"
android:orientation="vertical" xmlns:swipe="http://schemas.android.com/apk/res/com.example.zhy_swipelistview02"> <include
layout="@layout/main_title"
android:focusable="true" /> <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" > <com.fortysevendeg.swipelistview.SwipeListView
android:id="@+id/id_swipelistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
swipe:swipeActionLeft="reveal"
swipe:swipeBackView="@+id/id_back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="@+id/id_front"
swipe:swipeMode="left"
swipe:swipeOffsetLeft="200dip"
swipe:swipeOpenOnLongPress="false" /> <TextView
android:id="@+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableTop="@drawable/no_chat"
android:text="木有联系人"
android:textColor="#ffb7b7b7"
android:textSize="14.0sp"
android:visibility="gone" />
</FrameLayout> <requestFocus /> </LinearLayout>
item的布局文件:
<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" > <LinearLayout
android:id="@+id/id_back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffcccccc"
android:gravity="center|right" > <Button
android:id="@+id/id_remove"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="4dp"
android:background="@drawable/red_button"
android:text="Delete"
android:textColor="#fff" >
</Button>
</LinearLayout> <LinearLayout
android:id="@+id/id_front"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff" > <TextView
android:id="@+id/id_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000"
android:textSize="25sp" >
</TextView>
</LinearLayout> </FrameLayout>
注意对应布局的id和swipeListView中的frontView和backView的Id一致。
package com.example.zhy_swipelistview02; import java.util.ArrayList;
import java.util.List; import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window; import com.fortysevendeg.swipelistview.BaseSwipeListViewListener;
import com.fortysevendeg.swipelistview.SwipeListView; public class MainActivity extends Activity
{ protected static final String TAG = "Activity";
private SwipeListView mSwipeListView;
private DataAdapter mAdapter;
private List<String> mDatas; @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); initDatas(); mSwipeListView = (SwipeListView) findViewById(R.id.id_swipelistview);
mAdapter = new DataAdapter(this, mDatas , mSwipeListView);
mSwipeListView.setAdapter(mAdapter); mSwipeListView.setSwipeListViewListener(new BaseSwipeListViewListener()
{
@Override
public void onChoiceChanged(int position, boolean selected)
{
Log.d(TAG, "onChoiceChanged:" + position + ", " + selected);
} @Override
public void onChoiceEnded()
{
Log.d(TAG, "onChoiceEnded");
} @Override
public void onChoiceStarted()
{
Log.d(TAG, "onChoiceStarted");
} @Override
public void onClickBackView(int position)
{
Log.d(TAG, "onClickBackView:" + position);
} @Override
public void onClickFrontView(int position)
{
Log.d(TAG, "onClickFrontView:" + position);
} @Override
public void onClosed(int position, boolean fromRight)
{
Log.d(TAG, "onClosed:" + position + "," + fromRight);
} @Override
public void onDismiss(int[] reverseSortedPositions)
{
Log.d(TAG, "onDismiss"); } @Override
public void onFirstListItem()
{
Log.d(TAG, "onFirstListItem");
} @Override
public void onLastListItem()
{
Log.d(TAG, "onLastListItem");
} @Override
public void onListChanged()
{
Log.d(TAG, "onListChanged"); mSwipeListView.closeOpenedItems(); } @Override
public void onMove(int position, float x)
{
Log.d(TAG, "onMove:" + position + "," + x);
} @Override
public void onOpened(int position, boolean toRight)
{
Log.d(TAG, "onOpened:" + position + "," + toRight);
} @Override
public void onStartClose(int position, boolean right)
{
Log.d(TAG, "onStartClose:" + position + "," + right);
} @Override
public void onStartOpen(int position, int action, boolean right)
{
Log.d(TAG, "onStartOpen:" + position + "," + action + ","
+ right);
}
});
} private void initDatas()
{
mDatas = new ArrayList<String>();
for (int i = 'A'; i <= 'Z'; i++)
mDatas.add((char) i + "");
} }
Adapter:
package com.example.zhy_swipelistview02; import java.util.List; import com.fortysevendeg.swipelistview.SwipeListView; import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView; public class DataAdapter extends BaseAdapter
{ private List<String> mDatas;
private LayoutInflater mInflater;
private SwipeListView mSwipeListView ; public DataAdapter(Context context, List<String> datas , SwipeListView swipeListView)
{
this.mDatas = datas;
mInflater = LayoutInflater.from(context);
mSwipeListView = swipeListView;
} @Override
public int getCount()
{
return mDatas.size();
} @Override
public Object getItem(int position)
{
return mDatas.get(position);
} @Override
public long getItemId(int position)
{
return position;
} @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;
} }
代码相当简单,MainActivity里面设置了监听事件,可以使用Demo的时候,观察触发的事件的输出,如果有特殊需求可以做一些操作。
版权声明:本文为博主原创文章,未经博主允许不得转载。
SwipeListView 详解 实现微信,QQ等滑动删除效果的更多相关文章
- Android listview 侧滑 SwipeListView 详解 实现微信,QQ等滑动删除效果
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/28508769 今天看别人项目,看到别人使用了SwipeListView,Goog ...
- SwipeListView 具体解释 实现微信,QQ等滑动删除效果
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/28508769 今天看别人项目,看到别人使用了SwipeListView,Goog ...
- 【转】Android 实现ListView的滑动删除效果
http://www.cnblogs.com/weixiao870428/p/3524055.html http://download.csdn.net/download/love_javc_you/ ...
- 腾讯技术分享:GIF动图技术详解及手机QQ动态表情压缩技术实践
本文来自腾讯前端开发工程师“ wendygogogo”的技术分享,作者自评:“在Web前端摸爬滚打的码农一枚,对技术充满热情的菜鸟,致力为手Q的建设添砖加瓦.” 1.GIF格式的历史 GIF ( Gr ...
- 原生H5页面模拟APP左侧滑动删除效果
话不多说,往左侧滑动,显示删除,我们先来看一下效果图:如下: 这个布局我就不多说,反正就是一行ul,li, class名“item” js代码如下: $(".item").on(& ...
- 详解封装微信小程序组件及小程序坑(附带解决方案)
一.序 上一篇介绍了如何从零开发微信小程序,博客园审核变智障了,每次代码都不算篇幅,好好滴一篇原创,不到3分钟从首页移出来了.这篇介绍一下组件封装和我的踩坑历程. 二.封装微信小程序可复用组件 首先模 ...
- View绘制详解(五),draw方法细节详解之View的滚动/滑动问题
关于View绘制系列的文章已经完成了四篇了,前面四篇文章主要带小伙伴们熟悉一下View的体系的整体框架.View的测量以及布局等过程,从本篇博客开始,我们就来看看View的绘制过程.View的绘制涉及 ...
- 微信小程序实现滑动删除效果
在一些app中,随处可见左滑动的效果,在微信小程序中,官方并未提供相关组件,需要我们自己动手写一个类似的效果 下面仅列举出核心代码,具体的优化需要根据你自身的需求 <view class='li ...
- 模仿qq列表信息滑动删除效果
这个效果的完成主要分为两个部分 自定义view作为listview的列表项 一个view里面包括 显示头像,名字,消息内容等的contentView和滑动才能显示出来的删除,置顶的右边菜单menuVi ...
随机推荐
- Gradle 1.12用户指南翻译——第四十四章. 分发插件
本文由CSDN博客貌似掉线翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- mybatis源码之BaseStatementHandler
/** * @author Clinton Begin */ public abstract class BaseStatementHandler implements StatementHandle ...
- 提高HBase写性能
以下为使用hbase一段时间的三个思考,由于在内存充足的情况下hbase能提供比较满意的读性能,因此写性能是思考的重点.希望读者提出不同意见讨论 1 autoflush=false的影响 无论是官方还 ...
- javascript中通过元素id和name直接取得元素
我们知道一些第三方的js库对如何快速选取html中的元素做了一些简化,貌似十分高深莫测,其实也不然.而且js本身自带了对于特殊元素的简便选取的方法,下面就为大家简单介绍下. 在html中,一般最直接的 ...
- Fullpage.js全屏滚动jQuery插件
兼容性: 支持 IE8+ 及其他现代浏览器. 主要功能: 1.支持鼠标滚动: 2.支持前进后退键盘控制; 3.多个回调函数; 4.支持手机.移动设备; 5.支持窗口缩放自动调整; 6.可设置滚动宽度. ...
- convert sorted list to binary search tree(将有序链表转成平衡二叉搜索树)
Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...
- Python高阶函数之 - 装饰器
高阶函数: 1. 函数名可以作为参数传入 2. 函数名可以作为返回值. python装饰器是用于拓展原来函数功能的一种函数 , 这个函数的特殊之处在于它的返回值也是一个函数 , 使用pyth ...
- dll附加依赖项查看——dumpbin 命令
VS自带工具 查看程序或动态链接库需要的动态链接库 dumpbin /dependents d:\test.exe 查看动态链接库的输出函数 dumpbin /exports d:\libmysq ...
- 关于在IJ中使用maven projects 的Lifecycle中打包package报expected START_TAG or END_TAG not TEXT
报错指定到maven本地仓库下的settings.xml某一行,如下列JDK配置: <profiles> <profile> <id>jdk-1.8</ ...
- php进阶篇
字符串调用: $name = 'eco'; echo $name; //eco //双引号会解析变量 echo "$name"; //eco //单引号不会解析变量 echo '$ ...