Dividers-For-RecyclerView

简介::clipboard: A simple demo to demonstrate how to draw dividers for RecyclerView
更多:作者   提 Bug   
标签:

This is just a simple demo app to demonstrate how to draw dividers for RecyclerView.

RecyclerView doesn't provide straightforward interface for drawing dividers of lists. But actually it provides us a much more flexible way to draw dividers. We use RecyclerView.ItemDecoration to decorate RecyclerView's tiles with dividers or anything you want. That is also why it is called ItemDecoration.

There are three different implemetations of dividers.

As described in Meterial Design Guidelines:

The divider sits within the baseline of the tile.

So I would suggest using OverlayDivider or InsetDivider. OverlayDivider draws dividers on the tiles, needing no extra inset. InsetDivider can draw dividers on or underneath the tiles.

Usage

  • UnderneathDivider
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.addItemDecoration(new UnderneathDivider(this, UnderneathDivider.VERTICAL_LIST));
    
  • OverlayDivider
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.addItemDecoration(new OverlayDivider(this, OverlayDivider.VERTICAL_LIST));
    
  • InsetDivider ```java ItemDecoration divider = new InsetDivider.Builder(this)
                          .orientation(InsetDivider.VERTICAL_LIST) 
                          .dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height))
                          .color(getResources().getColor(R.color.colorAccent))
                          .insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0)
                          .overlay(true)
                          .build(); 
    

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(divider); ```

License

Copyright 2016 gejiaheng

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 开发经验分享
用了一年多的理财推荐