在存在的View上布局和画分割线 – DividerDrawable

DividerDrawable

This library can help you easily layout and draw dividers on existing views. For better performance, don’t create new views for drawing dividers anymore, use drawable instead.

Install

repositories {
    maven { url "https://jitpack.io" }
}
dependencies {
    compile 'com.github.nekocode:DividerDrawable:{lastest-version}'
}

Usage

Obtain a newDividerDrawableinstance.

DividerDrawable dividerDrawable = new DividerDrawable(paint);

Similar to the view layout, theDividerDrawablealso has a layout that can help draw divider to the relative position of the container(view/drawable/canvas).

dividerDrawable.getLayout()
        .setOrientation(DividerLayout.ORIENTATION_VERTICAL)
        .setAlign(DividerLayout.ALIGN_PARENT_BOTTOM)
        .setCenter(DividerLayout.CENTER_HORIZONTAL)
        .setMarginBottomDp(20);

You can useDividerUtilsto easily combine the divider drawable to your existing backgroud drawable.

DividerUtils.addDividersTo(textView, dividerDrawable);

If you changed the divider’s layout params, don’t forget to notify the changes.

dividerDrawable.notifyLayoutChanged();

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:在存在的View上布局和画分割线 – DividerDrawable