Giter Site home page Giter Site logo

ccy0122 / focuslayoutmanager Goto Github PK

View Code? Open in Web Editor NEW
832.0 8.0 76.0 22.1 MB

有焦点item的水平/垂直滚动RecyclerView-LayoutManager。仿Android豆瓣书影音“推荐“频道列表布局

License: Apache License 2.0

Java 100.00%
android recyclerview recyclerview-layoutmanager layoutmanager douban

focuslayoutmanager's Introduction

Download

FocusLayoutManager

有焦点item的水平/垂直滚动RecyclerView-LayoutManager。仿Android豆瓣书影音“推荐“频道列表布局

效果


截图:


GIF:
gif1 gif2


可自己监听滚动编写效果,如修改成仿MacOS文件浏览:

依赖

implementation 'com.ccy:FocusLayoutManager:1.0.2'
// (or api)

使用

 focusLayoutManager =
                new FocusLayoutManager.Builder()
                        .layerPadding(dp2px(this, 14))
                        .normalViewGap(dp2px(this, 14))
                        .focusOrientation(FocusLayoutManager.FOCUS_LEFT)
                        .isAutoSelect(true)
                        .maxLayerCount(3)
                        .setOnFocusChangeListener(new FocusLayoutManager.OnFocusChangeListener() {
                            @Override
                            public void onFocusChanged(int focusdPosition, int lastFocusdPosition) {
                                
                            }
                        })
                        .build();
recyclerView.setLayoutManager(focusLayoutManager);

各属性意义见图:

注意:因为item在不同区域随着滑动会有不同的缩放(受动画控制),所以实际视觉上堆叠view的间距、普通view的间距未必等于layerPadding、normalViewGap

调整动画效果:

                new FocusLayoutManager.Builder()
                        ......
                        .setSimpleTrasitionListener(new FocusLayoutManager.SimpleTrasitionListener() {
                             @Override
                            public float getLayerViewMaxAlpha(int maxLayerCount) {
                                return super.getLayerViewMaxAlpha(maxLayerCount);
                            }

                            @Override
                            public float getLayerViewMinAlpha(int maxLayerCount) {
                                return super.getLayerViewMinAlpha(maxLayerCount);
                            }

                            @Override
                            public float getLayerChangeRangePercent() {
                                return super.getLayerChangeRangePercent();
                            }
                            //and more
                            
                            //更多可重写方法和释义见接口声明
                        })
                        .build();

自定义动画/滚动监听:

如果你想在滑动时不仅仅改变item的大小、透明度,你有更多的想法,可以监听TrasitionListener,该监听暴露了很多关键布局数据,

            ......
            .setSimpleTrasitionListener(null) //如果默认动画不想要,移除之。or use removeTrasitionlistener(XXX) 
            .addTrasitionListener(new FocusLayoutManager.TrasitionListener() {
                            @Override
                            public void handleLayerView(FocusLayoutManager focusLayoutManager,
                                                        View view, int viewLayer,
                                                        int maxLayerCount, int position,
                                                        float fraction, float offset) {
                                
                            }

                            @Override
                            public void handleFocusingView(FocusLayoutManager focusLayoutManager,
                                                           View view, int position,
                                                           float fraction, float offset) {

                            }

                            @Override
                            public void handleNormalView(FocusLayoutManager focusLayoutManager, View view, int position, float fraction, float offset) {

                            }
                        })

各参数意义见接口注释。 实际上SimpleTrasitionListener内部就会被转为TrasitionListener。可参考转换类是怎么做的:TrasitionListenerConvert

源码解析

https://blog.csdn.net/ccy0122/article/details/90515386

focuslayoutmanager's People

Contributors

ccy0122 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

focuslayoutmanager's Issues

无限循环滚动效果

请问如何修改LayoutManager的方式才能达到无限循环滚动呢?
参考demo设置adapter会出现闪烁,我之前是非循环的状态。

Failed to execute aapt

你好,使用你的这个库,会出现Failed to execute aapt,可能是跟我项目里冲突了..

间距问题

微信图片_20200228134626

您好,图片在放大的时候,会压缩左边堆叠区域的间距,与右边普通区域的间距不一致,这个问题怎么办呐?

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.