• Stars
    star
    455
  • Rank 96,175 (Top 2 %)
  • Language
    Java
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android 层叠卡片控件,仿"探探app"

效果图

StackLayout

功能

  • 自定义卡片的堆叠效果
  • 自定义卡片移除动画
  • 支持加载更多

使用方式

gradle dependency

// 1. Add it in your root build.gradle at the end of repositories:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

// 2. Add the dependency in your app/build.gradle
dependencies {
    compile 'com.github.fashare2015:StackLayout:1.0.0'
}

xml布局

  • 父布局使用clipChildren="false", 使之能全屏拖动
<RelativeLayout
    ...
    android:clipChildren="false">

    <com.fashare.stack_layout.StackLayout
        android:id="@+id/stack_layout"
        android:layout_width="match_parent"
        android:layout_height="500dp"/>

</RelativeLayout>

Adapter

用法基本同RecyclerView,不赘述。

mStackLayout = (StackLayout) findViewById(R.id.stack_layout);
mStackLayout.setAdapter(mAdapter = new MyAdapter(mData = new ArrayList<>()));

// 刷新数据
mData.addAll(...);
mAdapter.notifyDataSetChanged();

PageTransformer:堆叠效果、滑动动画

内置了三个效果,即gif效果图上的效果。

mStackLayout.addPageTransformer(
        new StackPageTransformer(),     // 堆叠
        new AlphaTransformer(),         // 渐变
        new AngleTransformer()          // 角度
);

自定义:根据position区分状态,做相应的动画。详见demo和接口注释。

position                 状态                    
[-1, -1] 完全移出屏幕, 待remove状态
(-1, 0) 手指拖动状态
[0, 栈内页面数) 栈中状态
[栈内页面数, 总页面数) 显示不下, 待显示状态

OnSwipeListener: 滑动结果回调

接口作用:(各参数定义见接口注释)

  • 区分向左移除、还是向右移除
  • 移除后,可做loadmore动作
mStackLayout.setOnSwipeListener(new StackLayout.OnSwipeListener() {
    @Override
    public void onSwiped(View swipedView, int swipedItemPos, boolean isSwipeLeft, int itemLeft) {
        toast((isSwipeLeft? "往左": "往右") + "移除" + mData.get(swipedItemPos) + "." + "剩余" + itemLeft + "项");

        // 少于5条, 加载更多
        if(itemLeft < 5){
            // TODO: loadmore
        }
    }
});

实现细节

控件实现细节介绍

参考

https://github.com/flschweiger/SwipeStack

https://github.com/xiepeijie/SwipeCardView

https://github.com/mcxtzhang/ZLayoutManager

https://github.com/yuqirong/CardSwipeLayout

https://github.com/xmuSistone/android-card-slide-panel

More Repositories

1

ActivityTracker

A FloatingView to show current topActivity in the activity stack.
Java
606
star
2

MVVM-JueJin

高仿"掘金Android App": databinding + kotlin + rx 的优雅实践。(持续打磨中~)
Java
397
star
3

TimerView

一个解耦良好的计时控件,可自由扩展。
Java
389
star
4

HoverView

一个底部抽屉。它可以悬停在中间,随着滑动自然过度到全屏
Java
194
star
5

LinkedScrollDemo

一个仿饿了么订餐页面的双列表联动Demo
Java
110
star
6

StackPageTransformer

A PageTransformer for ViewPager to show as stack!!!
Java
70
star
7

HelloKotlin

An summarize of kotlin with some demo.
Kotlin
44
star
8

SmallHelper-IDEA-Plugin

【IDEA插件】为插件化框架 Small 建立页面索引和快速跳转
Kotlin
43
star
9

NoViewHolder

No ViewHolder, No Adapter!!! 基于反射实现 DATA 和 VIEW 的绑定,不知 ViewHolder 为何物。
Java
41
star
10

AOSP_Indexer

为AOSP native代码建立索引
CMake
38
star
11

java-sugar

Kotlin
26
star
12

Dynamic-Load-Learning

Kotlin
22
star
13

ShareElementDemo

android 过场动画 Demo,基于 ShareElement。同时实现下拉返回上一个 Activity。
Java
20
star
14

gradle-screen-record

A GIF recorder, based on gradle script to record screen in Android Device, and the record (XXX.gif) will be auto uploaded to your PC.
Shell
20
star
15

DependencyBehavior

一个 demo, 用于分析 CoordinatorLayout 依赖机制
Java
5
star
16

XiaChuFang-ReactNative

高仿下厨房app, ReactNative版
JavaScript
2
star
17

apt_for_viewholder

just like ButterKnife, generate java code by @ViewHolder and @Adapter during compile time.
Java
1
star
18

PolygonImageView

正多边形边框的自定义ImageView
Java
1
star
19

my_rxjava_demo

Java
1
star