android中自定义标签详解

来源:互联网 发布:微信公众平台回调域名 编辑:程序博客网 时间:2024/06/14 22:44

来源:http://wenku.baidu.com/view/0f031dd533d4b14e85246896.html


Android中attr自定义标签详解 (2012-05-24 10:38:36)转载▼
标签: 杂谈 分类: android内核剖析
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:wen=http://schemas.android.com/apk/res/com.iteye.googlers
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="wrap_content">


第二行是自定义标签。


格式如上,其中“xmlns:wen”冒号后面是标签名,在下面使用时(只对当前文件可用)


<TextView  wen:属性名/>


“com.iteye.googlers”是你的工程包名。




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"
                     />

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 日本新干线车票丢了怎么办 房间太干燥怎么办又热 薄荷叶子全干了怎么办 水培栀子花叶子蔫了怎么办 薄荷叶叶边干了怎么办 碗莲叶子发黑腐烂怎么办 龟背叶叶子蔫了怎么办 夏天龟背竹蔫了怎么办 春羽叶子长黄斑怎么办 百合竹叶子发黄掉落怎么办 凤尾蕨叶子蔫了怎么办 绿地珊瑚蕨干了怎么办 翠云草叶子蔫了怎么办 珊瑚蕨叶子烂了怎么办 黑骨茶叶子黑斑怎么办 外场主持没有人互动怎么办 企业年报填错了怎么办 手机忘了放哪了怎么办 燃气卡车没气了怎么办 老房子拆了重建怎么办 加了差的汽油怎么办 事业单位未满5年怎么办 小学孩子不会制订学习计划怎么办 忘记提交原创怎么办百度熊掌号 计算机一级报名表填错了怎么办 离婚了不给孩子生活费怎么办 点击爱奇艺系统提示停止运行怎么办 电视机图像颜色变了怎么办 10万签约被拒怎么办 钢琴弹奏中的折指怎么办! 吉他琴头旋钮将琴头扭坏了怎么办? 1岁幼儿不爱吃饭怎么办 3岁幼儿不爱吃饭怎么办 4岁幼儿不爱吃饭怎么办 买票买了点映 怎么办 一年级孩子注意力不集中怎么办 孩子上一年级注意力不集中怎么办 普宁二中初一新生住宿怎么办 小学入学普查错过了怎么办 初一的孩子不爱学习怎么办 初一孩子出现厌学情况怎么办