Skip to content

Instantly share code, notes, and snippets.

@tcw165
Created October 11, 2018 16:24
Show Gist options
  • Select an option

  • Save tcw165/e410df44010fed96ed93a72b4cad3790 to your computer and use it in GitHub Desktop.

Select an option

Save tcw165/e410df44010fed96ed93a72b4cad3790 to your computer and use it in GitHub Desktop.
constructor(...) : super(...) {
val a = context.theme.obtainStyledAttributes(
attrs,
R.styleable.StyledRecyclerView, 0, 0)
decorateView(a, getOrientation(attrs))
a.recycle()
}
private fun decorateView(
typedArray: TypedArray,
orientation: Int
) {
// Divider and the mode
if (typedArray.hasValue(R.styleable.StyledRecyclerView_rvDividerDrawable)) {
val dividerDrawable = typedArray.getDrawable(R.styleable.StyledRecyclerView_rvDividerDrawable)
val dividerMode = typedArray.getInt(R.styleable.StyledRecyclerView_rvDividerMode, DividerMode.SHOW_DIVIDER_NONE)
val decoration = DrawableDividerDecoration(
dividerDrawable = dividerDrawable,
dividerMode = dividerMode)
addItemDecoration(decoration)
}
// Preview list item
if (isInEditMode) {
layoutManager = LinearLayoutManager(context, orientation, false)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment