Junior — Middle
Tell about your experience using Views in user interface development.
sobes.tech AI
Answer from AI
In Android development, View is the base class for all user interface components. My experience includes creating custom Views to implement unique interface elements, as well as working with ready-made widgets such as TextView, Button, RecyclerView.
For example, I have created a custom View for displaying a chart with dynamic data, overriding the onDraw and onMeasure methods for proper display and adaptation to screen size.
Here's an example of a simple custom View in Kotlin:
class CustomView(context: Context, attrs: AttributeSet) : View(context, attrs) {
private val paint = Paint().apply {
color = Color.BLUE
strokeWidth = 5f
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
canvas.drawLine(0f, 0f, width.toFloat(), height.toFloat(), paint)
}
}