Android自定义控件属性详细介绍

Android自定义控件属性详细介绍,第1张

概述 Android自定义控件属性详细介绍1.reference:参考某一资源ID。    (1)属性定义:

 AndroID自定义控件属性详细介绍

1. reference:参考某一资源ID。 

    (1)属性定义:

 <declare-styleable name = "名称">          <attr name = "background" format = "reference" />      </declare-styleable> 

     (2)属性使用:

  <ImageVIEw           androID:layout_wIDth = "42dip"           androID:layout_height = "42dip"           androID:background = "@drawable/图片ID"           />

2. color:颜色值。

     (1)属性定义:

       <declare-styleable name = "名称">          <attr name = "textcolor" format = "color" />      </declare-styleable>

        (2)属性使用:     

          <TextVIEw           androID:layout_wIDth = "42dip"           androID:layout_height = "42dip"           androID:textcolor = "#00FF00"           />

 3. boolean:布尔值。 

    (1)属性定义:            

       <declare-styleable name = "名称">          <attr name = "focusable" format = "boolean" />      </declare-styleable> 

    (2)属性使用:

        <button          androID:layout_wIDth = "42dip"          androID:layout_height = "42dip"          androID:focusable = "true"          />

 4. dimension:尺寸值。

     (1)属性定义: 

      <declare-styleable name = "名称">          <attr name = "layout_wIDth" format = "dimension" />      </declare-styleable>

     (2)属性使用:            

        <button          androID:layout_wIDth = "42dip"          androID:layout_height = "42dip"          />

 5. float:浮点值。

     (1)属性定义:

      <declare-styleable name = "AlphaAnimation">          <attr name = "fromAlpha" format = "float" />          <attr name = "toAlpha" format = "float" />      </declare-styleable> 

    (2)属性使用:

       <Alpha          androID:fromAlpha = "1.0"          androID:toAlpha = "0.7"          />

6. integer:整型值。 

    (1)属性定义:     

<declare-styleable name = "AnimatedRotateDrawable">          <attr name = "visible" />          <attr name = "frameDuration" format="integer" />          <attr name = "framesCount" format="integer" />          <attr name = "pivotX" />          <attr name = "pivotY" />          <attr name = "drawable" />      </declare-styleable>

     (2)属性使用:      

   <animated-rotate          xmlns:androID = "http://schemas.androID.com/apk/res/androID"           androID:drawable = "@drawable/图片ID"           androID:pivotX = "50%"           androID:pivotY = "50%"           androID:framesCount = "12"           androID:frameDuration = "100"          />

 7. string:字符串。 

    (1)属性定义:

    <declare-styleable name = "MapVIEw">          <attr name = "APIKey" format = "string" />      </declare-styleable>

    (2)属性使用:

  <com.Google.androID.maps.MapVIEw          androID:layout_wIDth = "fill_parent"          androID:layout_height = "fill_parent"          androID:APIKey = "0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g"          />

   8. fraction:百分数。

     (1)属性定义: 

      <declare-styleable name="RotateDrawable">          <attr name = "visible" />          <attr name = "fromdegrees" format = "float" />          <attr name = "todegrees" format = "float" />          <attr name = "pivotX" format = "fraction" />          <attr name = "pivotY" format = "fraction" />          <attr name = "drawable" />      </declare-styleable> 

    (2)属性使用:          

 <rotate          xmlns:androID = "http://schemas.androID.com/apk/res/androID"          androID:interpolator = "@anim/动画ID"          androID:fromdegrees = "0"          androID:todegrees = "360"          androID:pivotX = "200%"          androID:pivotY = "300%"          androID:duration = "5000"          androID:repeatMode = "restart"          androID:repeatCount = "infinite"          />

 9. enum:枚举值。 

    (1)属性定义: 

      <declare-styleable name="名称">          <attr name="orIEntation">             <enum name="horizontal" value="0" />             <enum name="vertical" value="1" />          </attr>            </declare-styleable>

     (2)属性使用:

     <linearLayout          xmlns:androID = "http://schemas.androID.com/apk/res/androID"          androID:orIEntation = "vertical"          androID:layout_wIDth = "fill_parent"          androID:layout_height = "fill_parent"          >      </linearLayout>

 10. flag:位或运算

     (1)属性定义:

  <declare-styleable name="名称">          <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>            </declare-styleable>

       (2)属性使用: 

     <activity          androID:name = ".StyleAndthemeActivity"          androID:label = "@string/app_name"          androID:windowsoftinputMode = "stateUnspecifIEd | stateUnchanged | stateHIDden">          <intent-filter>             <action androID:name = "androID.intent.action.MAIN" />             <category androID:name = "androID.intent.category.LAUNCHER" />          </intent-filter>       </activity>

      注意: 

     属性定义时可以指定多种类型值。

    (1)属性定义:

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

     (2)属性使用: 

       <ImageVIEw           androID:layout_wIDth = "42dip"           androID:layout_height = "42dip"           androID:background = "@drawable/图片ID|#00FF00"           />

 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

总结

以上是内存溢出为你收集整理的Android自定义控件属性详细介绍全部内容,希望文章能够帮你解决Android自定义控件属性详细介绍所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1146263.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存