Skip to content

Instantly share code, notes, and snippets.

@aqua30
Last active March 6, 2022 18:54
Show Gist options
  • Save aqua30/5bfab7c7027d379567adc1004aa1a79a to your computer and use it in GitHub Desktop.
Save aqua30/5bfab7c7027d379567adc1004aa1a79a to your computer and use it in GitHub Desktop.
Custom Layout
class CurvedContainer @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
): LinearLayout(context, attrs, defStyleAttr) {
/* paint object for coloring the canvas */
private val mPaint = Paint()
/* path that will be drawn to achieve the shape */
private val path = Path()
/* arcs will create the effect of curved corners */
private val leftArc = RectF()
private val rightArc = RectF()
/* offset values for our curved corners */
private val xAxisOffset = 100f
private val yAxisOffset = 100f
init {
/* setting the background as transparent as we're drawing the view ourself */
setBackgroundColor(Color.TRANSPARENT)
setLayerType(View.LAYER_TYPE_HARDWARE, null)
mPaint.apply {
style = Paint.Style.FILL
color = Color.WHITE
isAntiAlias = true
clipChildren = true
}
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
}
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment