Skip to content

Latest commit

 

History

History
228 lines (162 loc) · 5.93 KB

README.md

File metadata and controls

228 lines (162 loc) · 5.93 KB

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.