Last active
March 6, 2022 18:54
-
-
Save aqua30/5bfab7c7027d379567adc1004aa1a79a to your computer and use it in GitHub Desktop.
Custom Layout
This file contains 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
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