Coder Social home page Coder Social logo

tvrecyclerview's Introduction

欢迎使用 TvRecyclerView Download

  • 针对TV端的特性对RecyclerView进行了适配与开发;
  • 优化TwoWayView在TV端的适配和延伸;
  • 支持v7包原生的LayoutManager;
  • 支持阿里vlayout的布局及其它第三方LayoutManager;

效果

Android Studio 集成

// support版本
implementation 'com.owen:tv-recyclerview:2.1.1.1'

// androidx版本
implementation 'com.owen:tv-recyclerview:3.0.0'

自定义属性

属性 值/类型 简介
tv_layoutManager string 指定LayoutManager
tv_selectedItemOffsetStart dimension 选中的item距离开始(上/左)的偏移量, 与tv_selectedItemIsCentered二选一
tv_selectedItemOffsetEnd dimension 选中的item距离结尾(右/下)的偏移量, 与tv_selectedItemIsCentered二选一
tv_selectedItemIsCentered boolean 选中居中, 与上面的偏移量二选一
tv_isMenu boolean 是否为菜单模式
tv_isMemoryFocus boolean 是否记忆焦点
tv_loadMoreBeforehandCount int 提前多少个开始加载更多
tv_optimizeLayout boolean 布局优化, 常用的LayoutManager作用不是很大,但对MetroGridLayoutManager这种计算量大的布局来说有一定的提升
tv_verticalSpacingWithMargins dimension 设置布局item间的竖向间距
tv_horizontalSpacingWithMargins dimension 设置布局item间的横向间距
自定义LayoutManager属性
tv_numColumns int 列数, GridLayoutManager及子类所拥有
tv_numRows int 行数, GridLayoutManager及子类所拥有
tv_laneCountsStr string 每块区域的列数, MetroGridLayoutManager所拥有, 格式 如:24,60,10
tv_isIntelligentScroll boolean 根据区域智能滚动, MetroGridLayoutManager所拥有

特性

  • 支持快速移动焦点不丢失;

  • 支持Item选中放大不叠压;

  • 多种选中和滚动方式:

    //选中指定项
    setSelection(int psotion);
    
    //选中指定项(平滑的滚动方式)
    setSelectionWithSmooth(int position)
    
    //滚动到指定位置, 可以指定便宜量, 可以指定是否获取焦点
    scrollToPositionWithOffset(int position, int offset, boolean isRequestFocus)
    
    //平滑的滚动到指定位置, 可以指定便宜量, 可以指定是否获取焦点
    smoothScrollToPositionWithOffset(int position, int offset, boolean isRequestFocus)
  • 监听回调

    //item选中、点击监听
    mRecyclerView.setOnItemListener(new TvRecyclerView.OnItemListener() {
        @Override
        public void onItemPreSelected(TvRecyclerView parent, View itemView, int position) {
                //上次选中
        }
    
        @Override
        public void onItemSelected(TvRecyclerView parent, View itemView, int position) {
                //当前选中
        }
    
        @Override
        public void onItemClick(TvRecyclerView parent, View itemView, int position) {
                //点击
        }
    });
    
    //焦点移动边界监听
    mRecyclerView.setOnInBorderKeyEventListener(new TvRecyclerView.OnInBorderKeyEventListener() {
                @Override
                public boolean onInBorderKeyEvent(int direction, View focused) {
                    switch (direction) {
                        case View.FOCUS_DOWN:
    
                            break;
                        case View.FOCUS_UP:
    
                            break;
                        case View.FOCUS_LEFT:
    
                            break;
                        case View.FOCUS_RIGHT:
    
                            break;
                    }
                    //返回true时,事件将会被拦截由你来控制焦点
                    return false;
                }
            });
    
    //加载更多监听
    mRecyclerView.setOnLoadMoreListener(new TvRecyclerView.OnLoadMoreListener() {
                @Override
                public boolean onLoadMore() {
                    mRecyclerView.setLoadingMore(true); //正在加载数据
                    mLayoutAdapter.appendDatas(); //加载数据
                    mRecyclerView.setLoadingMore(false); //加载数据完毕
                    return true; //是否还有更多数据
                }
            });
           

更详细的使用请见exmaple


扣 扣 群:484790001(注:加群时请写明来源及目的)

其它作品

焦点框框架TvFocusBorder

Tab框架TvTabLayout

Tv控件TvWidget

作者 owen

tvrecyclerview's People

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.