GithubHelp home page GithubHelp logo

sakebook / multilinedivider Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 2.0 4.5 MB

Multi divider in RecyclerView on Android.

License: Apache License 2.0

Java 1.61% Kotlin 96.46% Ruby 1.93%
android divide kotlin recyclerview multi-divider java android-library android-ui divider itemdecoration

multilinedivider's Introduction

MultiLineDivider

Multi divider in RecyclerView on Android.

Download Android Arsenal

wercker status

Vertical Horizontal
image image
Inset Dash
image image
Grid FullBleed
image image
Position Inverted
image image

  • Requirement
    • SDK Version 16+
    • (Use from Java)Kotlin Version 1.0.0+

Usage

Add dependencies

compile 'com.github.sakebook:MultiLineDivider:0.2.0@aar'

// Use from Java
compile "org.jetbrains.kotlin:kotlin-stdlib:kotlin_version"

Add to RecyclerView like in addItemDecoration

  • Java
MultiLineDivider multiLineDivider = new MultiLineDivider(this, LinearLayout.VERTICAL);
recyclerView.addItemDecoration(multiLineDivider);
  • Kotlin
val multiLineDivider = MultiLineDivider(this)
recyclerView.addItemDecoration(multiLineDivider)

And Implement VerticalDivider in ViewHolder

  • Java
public class YourViewHolder extends RecyclerView.ViewHolder implements VerticalDivider {

    public YourViewHolder(View itemView) {
        super(itemView);
    }

    @Override
    public int getHeight() {
        return this.itemView.getContext().getResources()
                .getDimensionPixelSize(R.dimen.small_margin);
    }

    @Override
    public int getDrawableRes() {
        return R.drawable.custom_divider;
    }

    @Nullable
    @Override
    // android.support.v4.util.Pair
    public Pair<Integer, Integer> getVerticalInset() {
        return null;
    }
}
  • Kotlin
class YourViewHolder(view: View): RecyclerView.ViewHolder(view), VerticalDivider {
    override val height = view.context.resources.getDimensionPixelSize(R.dimen.small_margin)
    override val drawableRes = R.drawable.custom_divider
    override val verticalInset: Pair<Int, Int>? = null
}

Custom

If you want to draw Horizontal divider

MultiLineDivider multiLineDivider = new MultiLineDivider(this, LinearLayout.HORIZONTAL);

and implements HorizontalDivider

If you don't want to draw divider

Implements NoDivider

If you want to inset in divider

@Nullable
@Override
// android.support.v4.util.Pair
public Pair<Integer, Integer> getVerticalInset() {
    int insetLeft = (int) resources.getDimension(R.dimen.list_padding);
    int insetRight = 0;
    return Pair.create(insetLeft, insetRight);
}

If you want to padding in grid

  • Java
public class YourViewHolder extends RecyclerView.ViewHolder implements GridDivider {

    public YourViewHolder(View itemView) {
        super(itemView);
    }

    @Override
    public int getPadding() {
        return itemView.getContext().getResources().getDimensionPixelSize(R.dimen.tiny_margin);
    }

    @Override
    public boolean getFullBleed() {
        return false;
    }
}
  • Kotlin
class YourViewHolder(view: View): RecyclerView.ViewHolder(view), GridDivider {
    override val padding = view.context.resources.getDimensionPixelSize(R.dimen.grid_padding)
    override val fullBleed = true
}

If you want to draw divider in specific position

  • Java
public class YourViewHolder extends RecyclerView.ViewHolder implements PositionDivider {

    public YourViewHolder(View itemView) {
        super(itemView);
    }

    @NotNull
    @Override
    public List<Integer> getPositions() {
        return Arrays.asList(2, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32, 42); // include "2"
    }

    @Override
    public boolean getInverted() {
        return false;
    }
}
  • Kotlin
class YourViewHolder(view: View): RecyclerView.ViewHolder(view), PositionDivider {
    override val positions = listOf(2, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32, 42)
    override val inverted = false
}

If you don't want to draw divider in specific position

Implements PositionDivider with inverted true

If you want to draw custom divider in specific position

Implements PositionDivider and VerticalDivider or HorizontalDivider

ProGuard

If you are using ProGuard you might need to add the following option:

-keep class com.sakebook.android.library.multilinedevider.*{ *; }

Sample in project sample/

LICENSE

Copyright (C) 2017 Shinya Sakemoto

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.

multilinedivider's People

Contributors

dependabot[bot] avatar sakebook avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

multilinedivider's Issues

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.