Code Monkey home page Code Monkey logo

griddivideritemdecoration's Introduction

GridDividerItemDecoration

简书相关介绍文章:https://www.jianshu.com/p/fb7e1a0749d6

这个GridDividerItemDecoration适用于适用RecyclerView时,采用GridLayoutManager时,间隔计算问题: 具体为:

  1. 可以在首尾列与父布局之间添加间隔
  2. item可以自己设置宽高,也可以程序自己自动生成
  3. 行与行之间的距离可以设置,列与列之间的距离自动计算

如图:

行间距

列间距

与父控件间距

解决的问题:

  1. 解决搜索到的GridItemDecoration,不能添加首尾列与父布局之间间隔的问题
  2. 解决item设置宽高后,列与列之间间隔大小不一的问题
  3. 解决设置间隔后,item大小不一的问题等。。。

使用方法: recyclerView.addItemDecoration(new GridDividerItemDecoration(this,Utils.dp2px(getContext(),20),Utils.dp2px(getContext(),15),true));

GridDividerItemDecoration构造函数有几种,分别可以设置:

  • 是否需要添加首尾列与父布局之间间隔;
  • 是否需要添加第一行与父布局的间隔;
  • 最后一行是否需要间隔等;

Adapter xml文件设置有两种Type:

  1. item_adpater_for_not_set_width_height.xml 此xml描述了不设置具体item 的宽高,由程序自己设置

  2. item_adpater_for_specific_width_height.xml 此xml描述了设置具体item 的宽高

griddivideritemdecoration's People

Contributors

haozi5460 avatar

Watchers

James Cloos avatar

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.