可以輕松地為您RecyclerViews創建分隔符的Android庫:Dividers

jopen 9年前發布 | 9K 次閱讀 Dividers Android開發 移動開發

Dividers是一個Android可以輕松地為您RecyclerViews創建分隔符。It supports a wide range of dividers from simple ones that apply to all your items equally to a system of selectors that apply different styles to each item.

Screenshots

Demo screenshot

Usage

The most easy way to start usingDividersis to create aDividerItemDecorationwith a layer and provide it to yourRecyclerViewas follows:

// Create a drawable for your divider
Drawable exampleDrawable = getResources().getDrawable(R.drawable.example_drawable);

// Create a DividerItemDecoration instance with a single layer and add it to your recycler view
RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(new Layer(DividerBuilder.get().with(exampleDrawable).build()));
recyclerView.addItemDecoration(itemDecoration);

If you want to use all the features ofDividersfollow this steps:

  • Create a collection of instances ofLayerwith the help ofLayersBuilderto define the drawables you want to apply. EachLayeris composed of:
  • An implementation of theSelectorinterface, defining which items are going to be affected by the layer. You can use one of the multiple implementations that come in the library or create your own.
public class HighRatingMovieSelector implements Selector {

  private final List<Movie> movies;
  private final int maxHighRating;

  public HighRatingMovieSelector(List<Movie> movies, int maxHighRating) {
    this.movies = movies;
    this.maxHighRating = maxHighRating;
  }

  @Override public boolean isPositionSelected(Position position) {
    return movies.get(position.getAbsoluteIndex()).getRating() >= maxHighRating;
  }

  @Override public EnumSet<Direction> getDirectionsByPosition(Position position) {
    return EnumSet.allOf(Direction.class);
  }
}

項目主頁:http://www.baiduhome.net/lib/view/home/1442134593573

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!