将布局与代码中的硬编码 dp、sp 改为引用 @dimen/dp_*、@dimen/sp_* 与 R.dimen.*; 资源名规则为整数部分与一位小数部分用下划线连接(如 12.5 → dp_12_5)。 在用户要求去掉魔法数、统一 dimen、替换 dp/sp 字面量或规范化尺寸引用时使用。
76
93%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
@dimen/dp_*、@dimen/sp_*Ndp / Nsp 或等价的 dp、sp 数值,改成 dimen 引用。values/dimens.xml 是否已有对应项:默认视为已存在,直接按规则写出 @dimen/... 与 R.dimen....。dp_,文字尺寸用 sp_。整数部分 + _ + 小数点后那一位数字(仅 一位 小数参与命名)。
_ 表示小数点,不是第二个「任意分隔符」。dp_12、sp_8,不要写成 dp_12_0(除非用户项目已有该风格再跟随项目)。| 原始数值(dp 或 sp,单位一致即可) | 资源名(dp 示例) | XML 引用 | 代码引用 |
|---|---|---|---|
| 0.5 | dp_0_5 | @dimen/dp_0_5 | R.dimen.dp_0_5 |
| 12.5 | dp_12_5 | @dimen/dp_12_5 | R.dimen.dp_12_5 |
| 12.5555 | dp_12_5(先截断为 12.5) | @dimen/dp_12_5 | R.dimen.dp_12_5 |
| 12 | dp_12 | @dimen/dp_12 | R.dimen.dp_12 |
sp 同理:12.5sp → @dimen/sp_12_5、R.dimen.sp_12_5。
对某个 dp 或 sp 的数值 v(只看数字部分):
v 为整数(或可视为整数):资源名为 dp_<整数> 或 sp_<整数>。v 有小数部分:将 v 截断到小数点后一位得到 v',拆成整数部分 a 与一位小数数字 b(b 为 0–9),资源名为 dp_<a>_<b> 或 sp_<a>_<b>。
v = 12.5555 → v' = 12.5 → a = 12, b = 5 → dp_12_5。v = 0.5 → v' = 0.5 → dp_0_5。android:padding="12.5dp"、tools:layout_margin="8sp" 等中的 字面量 改为 @dimen/dp_12_5、@dimen/sp_8 等形式;不要在属性值里再保留 dp/sp 后缀(dimen 条目自身已带单位语义)。tools: 或 app: 等命名空间,只替换尺寸字面量部分,其余属性名与命名空间不变。R.dimen.dp_12_5、R.dimen.sp_8 等,与上述命名一致。resources.getDimension(R.dimen.dp_12_5) 等;本 Skill 只规定 资源名与引用形式,不规定用 px 还是 dp 的封装工具类。dimens.xml 条目(除非用户明确要求创建资源文件)。10dp+2dp)若出现,本 Skill 未定义统一资源名:先向用户确认或按项目已有约定处理。3fa9400
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.