Y_DividerItemDecoration

简介:一个通用的 RecyclerView 的分割线,支持 LinearLayoutManager 和 GridViewLayoutManager
更多:作者   提 Bug   示例 APK   
标签:
recyclerview-divider-itemdecoration-分割线-

Y_DividerItemDecoration

A generic RecyclerView divider that supports LinearLayoutManager and GridLayoutManager. As long as you can describe the situation for the four directions(left、top、right、bottom) of each position , in principle, support any LayoutManager.

LinearLayoutManager 普通 GridViewLayoutManager 异形 GridLayoutManager

Features

  • LinearLayoutManager and GridLayoutManager are both supported
  • Customize the width and color of the divider
  • Flexibly control whether need show divider of the four directions(left、top、right、bottom) of each item or not

Download

Gradle

compile 'com.yanyusong.y_divideritemdecoration:y_divideritemdecoration:1.0

Maven

<dependency>
  <groupId>com.yanyusong.y_divideritemdecoration</groupId>
  <artifactId>y_divideritemdecoration</artifactId>
  <version>1.0</version>
  <type>pom</type>
</dependency>

Usage

Step1

Create an object to implement the abstract class Y_DividerItemDecoration. In the getItemSidesIsHaveOffsets (int itemPosition) method, you can decide whether need show divider for the four directions(left、top、right、bottom) of the item of position.

    class DividerItemDecoration extends Y_DividerItemDecoration {

        public DividerItemDecoration(Context context, int lineWidthDp, @ColorInt int colorRGB) {
            super(context, lineWidthDp, colorRGB);
        }

        @Override
        public boolean[] getItemSidesIsHaveOffsets(int itemPosition) {
            //clockwise order : left, top, right, bottom
            boolean[] isOffset = {false, false, false, true};//only show the divider of bottom by default
            return isOffset;
        }
    }

Step2

Add divider to RecyclerView ,And pass the width and color of the divider, width unit must be dp, color format must be 0xAARRGGBB,such as 0xff6c6c6c.

recyclerView.addItemDecoration(new DividerItemDecoration(this, 6, 0xff6c6c6c));

License

   Copyright  2017  yanyusong

   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.
Android 开发经验分享
Android 开发经验分享