【发布时间】:2015-10-27 14:39:38
【问题描述】:
我创建了一个带有属性的自定义视图。有没有办法在 Android Studio 中将这些属性与 android 工具一起使用?
例如:
<MyOwnCoolView
android:layout_width="96dp"
android:layout_height="96dp"
android:padding="3dp"
tools:dividerAngle="2"/>
attr 文件在哪里:
<resources>
<declare-styleable name="MyOwnCoolView">
<attr name="dividerAngle" format="float"/>
</declare-styleable>
【问题讨论】:
-
为什么要使用工具命名空间?您可以使用“schemas.android.com/apk/res-auto”命名空间。
-
拥有一个有价值的占位符。查看它在设计视图中的外观。稍后在运行时,此视图将获得各种值。
-
据我所知,设计预览也应该与“schemas.android.com/apk/res-auto”一起使用,请务必在类构造函数中检索值。
-
当然可以,但是虚拟值也保留在那里以用于发布。使用工具您不必担心“清理”虚拟数据
-
好吧,我终于明白了 :) 你应该编辑你的问题以明确这一点。如果你设置 tools:dividerAngle 会发生什么?什么都没有?
标签: android android-layout android-view android-xml android-tools-namespace