用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/DevonStee/OpenFlip --skill android-high-performance-custom-view命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
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
基于 SOC 职业分类
正在显示 SKILL.md
| 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