Skip to content

naseemakhtar994/MultiLineDivider

 
 

Repository files navigation

MultiLineDivider

Multi divider in RecyclerView on Android.

Download Android Arsenal

Vertical Horizontal Inset Dash
image image 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);
}

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.

About

Multi divider in RecyclerView on Android.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 86.4%
  • Java 13.6%