GithubHelp home page GithubHelp logo

stacklayout's Introduction

效果图

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

stacklayout's People

Contributors

fashare2015 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stacklayout's Issues

博主很棒,按着您的思路,学会了很多,但是还有一块不太明白,想请教一下。

第一个问题:
在StackPageTransformer中

 else if (position <= bottomPos) { //[0,mStackCount-1] 堆栈中
            int index = (int) position; //取整
            float minScale = mMaxScale * (float) Math.pow(mPowBase, index + 1);
            float maxScale = mMaxScale * (float) Math.pow(mPowBase, index);

我读了源码之后,我认为maxScale就是当前Position变化的大小.
而minScale是当前的下一层变化的大小.

这块不太确定,请楼主指点一下.

第二个问题:

第二个问题,我感觉楼主的实现方式是参考RecyclerView和ViewPager,跟着楼主把 这个控件实现,真的学到好多,感觉比以前更清晰了.

那么第二个问题是在这个控件中是否实现了RecyclerView的复用机制.

感谢博主~

源码有个地方,不太懂。

mMinScale = minScale;
      mMaxScale = maxScale;
      mStackCount = stackCount;

      if(mMaxScale < mMinScale)
          throw new IllegalArgumentException("The Argument: maxScale must bigger than minScale !");
      mPowBase = (float) Math.pow(mMinScale/mMaxScale, 1.0f/mStackCount);

这个mPowBase代表着是相邻两个基底的大小,这个计算过程,我没太看明白。。为什么这样做。。。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.