Skip to content

Instantly share code, notes, and snippets.

@seoft
Created January 12, 2020 03:45
Show Gist options
  • Save seoft/13f7fa3bbd05e616f71a2d2ead6ff4d4 to your computer and use it in GitHub Desktop.
Save seoft/13f7fa3bbd05e616f71a2d2ead6ff4d4 to your computer and use it in GitHub Desktop.
class ClickableRecyclerViewInCl @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
val rv = RecyclerView(context)
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return true
}
init {
rv.id = View.generateViewId()
this.addView(rv)
ConstraintSet().also { cs ->
cs.clone(this)
cs.connect(
rv.id,
ConstraintSet.LEFT,
ConstraintSet.PARENT_ID,
ConstraintSet.LEFT,
0
)
cs.connect(
rv.id,
ConstraintSet.TOP,
ConstraintSet.PARENT_ID,
ConstraintSet.TOP,
0
)
cs.applyTo(this)
}
rv.layoutParams.apply {
width = LayoutParams.MATCH_PARENT
height = LayoutParams.MATCH_PARENT
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment