Giter VIP home page Giter VIP logo

ladderlayoutmanager's Introduction

LadderLayoutManager

A card stack effect LayoutManger for android.

演示

vertical horizontal
vertical horizontal

Usage

  • create a new instance. then set it to RecyclerView directly
LadderLayoutManager llm = new LadderLayoutManager(1.5f, 0.85f, LadderLayoutManager.HORIZONTAL).
RecyclerView rcv = (RecyclerView)findViewById(R.id.rcv);
rcv.setLayoutManager(llm);

参数说明

/**
 * @param itemHeightWidthRatio childview的纵横比。所有childview都会按该纵横比展示
 * @param scale                chidview每一层级相对于上一层级的缩放量
 * @param orientation          布局方向 -纵向或者横向
 */
public LadderLayoutManager(float itemHeightWidthRatio, float scale, int orientation) {
    this.mItemHeightWidthRatio = itemHeightWidthRatio;
    this.mOrientation = orientation;
    this.mScale = scale;
    this.mChildSize = new int[2];
    this.mInterpolator = new DecelerateInterpolator();
}

Customizations

  • 设置childview的最大展示数量

    如果不设置,默认LadderLayoutManager将展示在空间允许范围的所有childview

    public void setMaxItemLayoutCount(int count) {
        mMaxItemLayoutCount = Math.max(2, count);
        if (getChildCount() > 0) {
            requestLayout();
        }
    }
  • 设置堆叠中的childview的展示高度

    如果不设置,默认展示高度为 横向布局childview宽度x0.2 / 纵向布局childview高度x0.2

    public void setChildPeekSize(int childPeekSize) {
        mChildPeekSizeInput = childPeekSize;
        mCheckedChildSize = false;
        if (getChildCount() > 0) {
            requestLayout();
        }
    }
  • 设置childview排列顺序

    /**
     * @param reverse 是否反向显示数据,默认false
     */
    public void setReverse(boolean reverse) {
        if (mReverse != reverse) {
            mReverse = reverse;
            if (getChildCount() > 0) {
                requestLayout();
            }
        }
    }
  • 设置消失点的偏移量

    演示参考 horizontal

    /**
     * @param offset 消失点的偏移量 范围[-1,1],默认0(居中)
     */
    public void setVanishOffset(float offset) {
        mVanishOffset = offset;
        if (getChildCount() > 0) {
            requestLayout();
        }
    }
  • 设置childview布局过程中的回调

    目前用于动态改变阴影、透明度

    public LadderLayoutManager setChildDecorateHelper(ChildDecorateHelper layoutHelper) {
        mDecorateHelper = layoutHelper;
        return this;
    }
    public interface ChildDecorateHelper {
        /**
         * @param child
         * @param posOffsetPercent childview相对于自身起始位置的偏移量百分比 范围[0,1)
         * @param layoutPercent    childview 在整个布局中的位置百分比
         * @param isBottom         childview 是否处于底部
         */
        void decorateChild(
        View child, float posOffsetPercent, float layoutPercent, boolean isBottom);
    }
    • 可以按照需求自定义,也可以直接使用位于LadderLayoutManager内的DefaultChildDecorateHelper
    public static class DefaultChildDecorateHelper implements ChildDecorateHelper {
        private float mElevation;
    
        public DefaultChildDecorateHelper(float maxElevation) {
            mElevation = maxElevation;
        }
    
        @Override
        public void decorateChild
        (View child, float posOffsetPercent, float layoutPercent, boolean isBottom) {
            ViewCompat.setElevation(child, (float) (layoutPercent * mElevation * 0.7 + 				mElevation * 0.3));
        }
    }

Extras

  • 配合LadderSimpleSnapHelper (继承自SnapHelper)使用, 使RecyclerView在滑动结束时定位到某个位置

    LadderLayoutManager llm = new LadderLayoutManager(1.5f, 0.85f, LadderLayoutManager.HORIZONTAL).
    rcv = (RecyclerView) findViewById(R.id.rcv);
    rcv.setLayoutManager(llm);
    
    new LadderSimpleSnapHelper().attachToRecyclerView(rcv);

项目实现过程中对于LayoutManger需要重写的方法参考了 CarouselLayoutManager

License

Copyright 2017 thunderpunch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

ladderlayoutmanager's People

Contributors

thunderpunch 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

ladderlayoutmanager's Issues

Change horizontal scrolling position to left

Hi this is a great library and it is very useful as well but i was trying to change the horiontal scrolling position to left from right i tried but it is very difficult for me to do it so please if you could help me out..

How to stop infinite scroll , needed like viewpager

I am implementing recyclerview to work like viewpager. This layout manager is too good but only one item should be scrolled at a time of swiping or scrolling event. How can be achieved?

I tried pagersnaphelper. But it is not working.

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.