Created
October 11, 2018 16:24
-
-
Save tcw165/e410df44010fed96ed93a72b4cad3790 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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