自定义View各个属性

format表示的属性类型可以为boolean, string, integer, dimension, float, reference, color, fraction, enum, flag及其混合。
(1) boolean表示布尔值,调用如 xx:attr1=”false”
(2) integer表示整型,调用如 xx:attr1=”1”
(3) dimension表示尺寸值,调用如 xx:attr1=”42dp”
(4) float表示浮点型,调用如 xx:attr1=”0.7”
(5) color表示颜色值,调用如 xx:attr1=”#00FF00”
(6) string表示字符串,调用如 xx:attr1=”#adbddd”
(7) reference表示参考某一资源id,调用如 xx:attr1 = “@drawable/图片ID”
(8) fraction表示百分数,调用如 xx:attr1=”30%”
以上类型定义都为

(9) enum表示枚举值,定义为

<attr name="enum_attr">
      <enum name="horizontal" value="0" />
      <enum name="vertical" value="1" />
</attr>

调用如 xx:attr1=”horizontal”

(10) flag表示位或运算,定义为

<attr name="windowSoftInputMode">
    <flag name = "stateUnspecified" value = "0" />
    <flag name = "stateUnchanged" value = "1" />
    <flag name = "stateHidden" value = "2" />
    <flag name = "stateAlwaysHidden" value = "3" />
    <flag name = "stateVisible" value = "4" />
    <flag name = "stateAlwaysVisible" value = "5" />
    <flag name = "adjustUnspecified" value = "0x00" />
    <flag name = "adjustResize" value = "0x10" />
    <flag name = "adjustPan" value = "0x20" />
    <flag name = "adjustNothing" value = "0x30" />
 </attr>

调用如:xx:attr1=”stateUnspecified | stateUnchanged | stateHidden”

(11) 混合类型,定义为

<declare-styleable name = "combine_type">
    <attr name = "background" format = "reference|color" />
</declare-styleable>

调用如 xx:attr1 = “@drawable/图片ID|#DDFF00”

相关文章
相关标签/搜索