원클릭으로
android-high-performance-custom-view
Best practices for 60fps custom View rendering with zero allocation in onDraw
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Best practices for 60fps custom View rendering with zero allocation in onDraw
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Guidance for creating effective modular skills for Claude. Use when creating or refining skills to ensure they are concise, follow progressive disclosure patterns, and provide appropriate degrees of freedom.
Guidelines for ensuring smooth and race-condition-free theme transitions in Android, specifically regarding icon tinting and state management.
Best practices for effective human-AI pair programming and communication
Clarify touch-target vs visual size when users ask to resize buttons without changing icons.
Choose whether the outer container acts as the touch proxy or remains a layout placeholder to control hit targets.
Expert guidance for creating soulful, industrial-grade Android native interfaces with Jetpack Compose, focusing on tactility, typography, and motion.
| name | Android High-Performance Custom View |
| description | Best practices for 60fps custom View rendering with zero allocation in onDraw |
Last Verified: 2026-01-23 Applicable SDK: Android 14+ (API 34+) Dependencies: None
This skill covers techniques for achieving smooth 60fps rendering in custom Android Views, focusing on memory efficiency and GPU optimization.
NEVER allocate objects inside onDraw():
// ❌ BAD - allocates every frame
override fun onDraw(canvas: Canvas) {
val paint = Paint()
val path = Path()
val rect = RectF()
// ...
}
// ✅ GOOD - pre-allocate at class level
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
private val path = Path()
private val rect = RectF()
override fun onDraw(canvas: Canvas) {
path.reset() // Reuse, don't recreate
// ...
}
Calculate complex paths in onSizeChanged, not onDraw:
private val clipPath = Path()
private val cardPath = Path()
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
// Pre-compute rounded rectangle path
cardPath.reset()
cardPath.addRoundRect(0f, 0f, w.toFloat(), h.toFloat(), cornerRadius, cornerRadius, Path.Direction.CW)
// Pre-compute clip regions
clipPath.set(cardPath)
tempPath.addRect(0f, 0f, w.toFloat(), h / 2f, Path.Direction.CW)
clipPath.op(tempPath, Path.Op.INTERSECT)
}
override fun onDraw(canvas: Canvas) {
canvas.clipPath(clipPath) // Use pre-computed path
// ...
}
Only recreate expensive objects when dimensions actually change:
private var lastWidth = 0
private var lastHeight = 0
private fun refreshGradientsIfNeeded(w: Int, h: Int) {
if (w == lastWidth && h == lastHeight) return
lastWidth = w
lastHeight = h
// Expensive shader creation
paint.shader = LinearGradient(
0f, 0f, 0f, h.toFloat(),
topColor, bottomColor,
Shader.TileMode.CLAMP
)
}
Enable hardware acceleration for animation-heavy views:
init {
setLayerType(LAYER_TYPE_HARDWARE, null)
}
When to use:
When NOT to use:
For views displaying text, cache measurement results:
private val textBoundsCache = mutableMapOf<String, Rect>()
private fun getTextBounds(text: String): Rect {
return textBoundsCache.getOrPut(text) {
Rect().also { paint.getTextBounds(text, 0, text.length, it) }
}
}
Avoid redundant recalculations for minor changes:
private var lastDimWidth = 0f
fun setDimensions(width: Float, height: Float) {
// Only update if change exceeds threshold
if (abs(width - lastDimWidth) < 0.5f) return
lastDimWidth = width
// Expensive recalculation...
}
new keywords inside onDraw()onSizeChanged()onDraw