翻翻git之---好看的卡片切换库 Swipecards
2016-02-18 10:41
435 查看
转载请注明出处:王亟亟的大牛之路
刚上班2,3天还没从放假的节奏中缓过来,总觉得懒洋洋的哈哈哈。继续之前的介绍一些好用/有意思/有学习意义的干活给大家,今天是Swipecards
地址:https://github.com/Diolor/Swipecards
效果:
在国内的一些社交类的App中也见过类似的实现。
How to use?
Gradle:[code]dependencies { compile 'com.lorentzos.swipecards:library:X.X.X@aar' }
Eclipse的话就要把源码都Copy进去了(还好东西不多)
简单的介绍下怎么使用
首先,在你的布局里面拽入这个控件
[code] <com.lorentzos.flingswipe.SwipeFlingAdapterView android:id="@+id/frame" android:background="#ffeee9e2" android:layout_width="match_parent" android:layout_height="match_parent" app:rotation_degrees="15.5" tools:context=".MyActivity" />
他有一些自定义的标签,像这样
[code] <declare-styleable name="SwipeFlingAdapterView"> <attr name="SwipeFlingStyle" format="reference"/> <attr name="rotation_degrees" format="float"/> <attr name="min_adapter_stack" format="integer"/> <attr name="max_visible" format="integer"/> </declare-styleable>
都是一些对控件进行配置的,具体的属性大家可以看下源码,这里就不做解释了
接下来那我们就在事物的Activity里获取这个控件(这边是用依赖注入做的)
[code] @InjectView(R.id.frame) SwipeFlingAdapterView flingContainer;
再给我们的控件添加数据源
[code] al = new ArrayList<>(); al.add("php"); al.add("c"); al.add("python"); al.add("java"); al.add("html"); al.add("c++"); al.add("css"); al.add("javascript"); arrayAdapter = new ArrayAdapter<>(this, R.layout.item, R.id.helloText, al ); flingContainer.setAdapter(arrayAdapter);
添加控件的事件监听
当卡片被移除,无论左右都会触发removeFirstObjectInAdapter()
左边触发onLeftCardExit()
右边出发onRightCardExit()
没数据了调用onAdapterAboutToEmpty()
滑动的过程中调用onScroll()
[code] flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() { @Override public void removeFirstObjectInAdapter() { // this is the simplest way to delete an object from the Adapter (/AdapterView) Log.d("LIST", "removed object!"); al.remove(0); arrayAdapter.notifyDataSetChanged(); } @Override public void onLeftCardExit(Object dataObject) { //Do something on the left! //You also have access to the original object. //If you want to use it just cast it (String) dataObject makeToast(MyActivity.this, "Left!"); } @Override public void onRightCardExit(Object dataObject) { makeToast(MyActivity.this, "Right!"); } @Override public void onAdapterAboutToEmpty(int itemsInAdapter) { // Ask for more data here al.add("XML ".concat(String.valueOf(i))); arrayAdapter.notifyDataSetChanged(); Log.d("LIST", "notified"); i++; } @Override public void onScroll(float scrollProgressPercent) { View view = flingContainer.getSelectedView(); view.findViewById(R.id.item_swipe_right_indicator).setAlpha(scrollProgressPercent < 0 ? -scrollProgressPercent : 0); view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercent > 0 ? scrollProgressPercent : 0); } });
还支持点击时间(就是没有滑,单纯的点)
[code] flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() { @Override public void onItemClicked(int itemPosition, Object dataObject) { makeToast(MyActivity.this, "Clicked!"); } }); }
源码在最上面的连接里有!!!
谢谢!!!
相关文章推荐
- rtx自定义面板不更新
- Python之计算器(第四天)
- 添加标签
- 遇到多个构造器参数时要考虑用构造器
- [转]实现微信浏览器内打开App Store链接
- 克隆KVM虚拟机
- C#设计模式09-装饰模式
- 多线程下载 显示进度 速度(转)
- JSONKit 在Xcode7下的问题
- C\C++常用库函数实现
- 【转】Oracle Object type 对象类型详解
- GCC-4.8.2 的安装
- convertRect
- 导出csv文件能在浏览器打开
- EF实现主从表自动生成主键保存
- 寻找SQL注入点
- 粗略地在iOS中使用URLManager架构
- mysql分表和表分区详解
- Shell脚本,包含了[分支 循环 数组 搜索 运算等基本功能]
- 线程池三:AsyncTask线程池