attrs文件

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <!-- attrs属性文件 -->
    <!--declare-styleable里标示的属性可以利用其父属性里的“内容(attr标签里的属性)”满足继承,
    不可利用其他declare·····里的私有内容(attr),如果需要调用其他declare······里的私有属性,需
    添加引用"(如LinearLayout调用ListView里name="divider"的属性)":源码?:
    //表示控件为Listview
    (1) <declare-styleable name="ListView">
     <attr name="divider" format="reference|color" />
     </declare-styleable>
     //LinearLayout布局控件
     <declare-styleable name="LinearLayout">
     <attr name="divider" />//此为引用(1)控件即ListView控件的私用属性
     </declare-styleable>
     以上两个组件都有共同的最终父类View,所以可以直接利用View里标示的属性“(如他们都可以在xml里用
    padding、background、margin、marginLeft等属性)”,如需引用其他declare-styleable
     内的属性,需在内部添加注明引用,如上所述,其他declare-styleable里的私有属性都可引用,不过需要内部
     注明。
     -->
     <!-- themes文件和styles文件对attrs中属性的引用,没搞清楚,貌似attrs文件里的属性值
     都可引用,但style时定义控件风格的,theme时定义整个application或activity样式的,作用范围
     不一样 -->
     <!--      ?以下引用方式通过attr属性
     <item name="dropdownListPreferredItemHeight">
     ?android:attr/listPreferredItemHeightSmall</item>
     直接引用属性值,如果定义多个此属性值,只能友情提示,不能多次第一一个属性值,唯一性,对于一个会报错的,如果你在
     你自定义的风格里设置的话应该会优先调用你自己设置的。
               -----------------------属性唯一性---------------------
     这个问号引用应该是根据attrs文件下的android:attr/listPreferredItemHeightSmall来遍历所有的有这个
  “属性(listPreferredItemHeightSmall)”的设置,然后就引用这个设置,如果关于这个属性的设置,超过一个,
  android内部应该就判断不了,就报错提示。
  这种一个属性有两个<item name="listPreferredItemHeightSmall">@·····</item>的话,如果直接在另一
  个<item name="dropdownListPreferredItemHeight">
     ?android:attr/listPreferredItemHeightSmall</item>
     属性下引用这个属性的话,应该会报错,唯一性,不报错应该有优先权问题出现,前提是都是?android:attr引用这个下的,
     ?attr/····名字和以上相同没事,不同文件下。
       -->
                     <!-- themes.xml(sdk内部)源码 -->
    <declare-styleable name="WindowAnimation">
        <!-- The animation used when a window is being added. -->
        <attr name="windowEnterAnimation" format="reference" />
        <!-- The animation used when a window is being removed. -->
        <attr name="windowExitAnimation" format="reference" />
        <!-- The animation used when a window is going from INVISIBLE to VISIBLE. -->
        <attr name="windowShowAnimation" format="reference" />
        <!-- The animation used when a window is going from VISIBLE to INVISIBLE. -->
        <attr name="windowHideAnimation" format="reference" />
        </declare-styleable>
        <!-- ListView控件的属性 -->
    <declare-styleable name="ListView">//表示组件为Listview
        <!-- Reference to an array resource that will populate the ListView.  For static content,
             this is simpler than populating the ListView programmatically. -->
        <attr name="entries" />//Listview的引用属性
        <!-- Drawable or color to draw between list items. -->
        <attr name="divider" format="reference|color" />//Listview的私有属性
        <!-- Height of the divider. Will use the intrinsic height of the divider if this
             is not specified. -->
        <attr name="dividerHeight" format="dimension" />
                          <!-- 此处省略 -->
    </declare-styleable>

    <!-- 以下列举了View的一部分属性 -->
    <declare-styleable name="View">
        <attr name="visibility">
            <!-- Visible on screen; the default value. -->
            <enum name="visible" value="0" />
            <!-- Not displayed, but taken into account during layout (space is left for it). -->
            <enum name="invisible" value="1" />
            <!-- Completely hidden, as if the view had not been added. -->
            <enum name="gone" value="2" />
        </attr>
        <!-- Sets the padding, in pixels, of the left edge; see {@link android.R.attr#padding}. -->
        <attr name="paddingLeft" format="dimension" />
        <!-- Sets the padding, in pixels, of the top edge; see {@link android.R.attr#padding}. -->
        <attr name="paddingTop" format="dimension" />
        <!-- Sets the padding, in pixels, of the right edge; see {@link android.R.attr#padding}. -->
        <attr name="paddingRight" format="dimension" />
        <!-- Sets the padding, in pixels, of the bottom edge; see {@link android.R.attr#padding}. -->
        <attr name="paddingBottom" format="dimension" />
        </declare-styleable>
         <!-- Standard orientation constant. -->
         <!-- Theme的一部分属性 -->
         <declare-styleable name="Theme">
    <attr name="orientation">
        <!-- Defines an horizontal widget. -->
        <enum name="horizontal" value="0" />//orientation的元素(值)
        <!-- Defines a vertical widget. -->
        <enum name="vertical" value="1" />
    </attr>
    </declare-styleable>
    <!-- 以下为LinearLayout的一部分属性 -->
     <declare-styleable name="LinearLayout">
        <!-- Should the layout be a column or a row?  Use "horizontal"
             for a row, "vertical" for a column.  The default is
             horizontal. -->
        <attr name="orientation" /><!-- 引用<declare-styleable name="Theme">的属性 -->
        <attr name="gravity" />
        <attr name="divider" />//对listview私有属性的引用
        <!-- Defines the maximum weight sum. If unspecified, the sum is computed
             by adding the layout_weight of all of the children. This can be
             used for instance to give a single child 50% of the total available
             space by giving it a layout_weight of 0.5 and setting the weightSum
             to 1.0. -->
        <attr name="weightSum" format="float" />
        <!-- When set to true, all children with a weight will be considered having
             the minimum size of the largest child. If false, all children are
             measured normally. -->
        <attr name="measureWithLargestChild" format="boolean" />
                                <!-- 此处省略 -->
    </declare-styleable>

    <eat-comment />
    <attr name="orientation">
        <!-- Defines an horizontal widget. -->
        <enum name="horizontal" value="0" />
        <!-- Defines a vertical widget. -->
        <enum name="vertical" value="1" />
    </attr>
    <eat-comment />
     <attr name="gravity">
        <!-- Push object to the top of its container, not changing its size. -->
        <flag name="top" value="0x30" />//gravity的可选值
        <!-- Push object to the bottom of its container, not changing its size. -->
        <flag name="bottom" value="0x50" />
        <!-- Push object to the left of its container, not changing its size. -->
        <flag name="left" value="0x03" />
        <!-- Push object to the right of its container, not changing its size. -->
        <flag name="right" value="0x05" />
        <!-- Place object in the vertical center of its container, not changing its size. -->
                                   <!-- 此处省略 -->
        <!-- Push object to the beginning of its container, not changing its size. -->
        <flag name="start" value="0x00800003" />
        <!-- Push object to the end of its container, not changing its size. -->
        <flag name="end" value="0x00800005" />
    </attr>
</resources>
时间: 2024-08-26 23:22:11

attrs文件的相关文章

android 自己定义控件属性(TypedArray以及attrs解释)

近期在捣鼓android 自己定义控件属性,学到了TypedArray以及attrs.在这当中看了一篇大神博客Android 深入理解Android中的自己定义属性.我就更加深入学习力一番.我就沿着这个学习,讲一下流程吧,兴许一篇还有应用. 1.attrs文件编写 <?xml version="1.0" encoding="utf-8"?> <resources> <attr name="titleText" for

android 自定义控件属性(TypedArray以及attrs解释)

最近在捣鼓android 自定义控件属性,学到了TypedArray以及attrs.在这其中看了一篇大神博客Android 深入理解Android中的自定义属性.我就更加深入学习力一番.我就沿着这个学习,讲一下流程吧,后续一篇还有应用. 1.attrs文件编写 <?xml version="1.0" encoding="utf-8"?> <resources> <attr name="titleText" forma

Android笔记自定义View之制作表盘界面

前言 最近我跟自定义View杠上了,甚至说有点上瘾到走火入魔了.身为菜鸟的我自然要查阅大量的资料,学习大神们的代码,这不,前两天正好在郭神在微信公众号里推送一片自定义控件的文章--一步步实现精美的钟表界面.正适合我这种菜鸟来学习,闲着没事,我就差不多依葫芦画瓢也写了一个自定义表盘View,现在纯粹最为笔记记录下来.先展示下效果图: 下面进入正题 自定义表盘属性 老规矩,先在attrs文件里添加表盘自定义属性 <declare-styleable name="WatchView"&

自定义进度条(圆形、横向进度条)

自定义进度条实现大体流程 1.自定义属性声明(attrs文件) 2.自定义属性获取 3.测量(onMeasure) 4.绘制(onDraw) 代码: attrs文件: <!-- 自定义声明 --> <attr name="progress_unreach_color" format="color"></attr> <attr name="progress_unreach_height" format=&q

android 自定义View(1)

自定义View: 第一步:创建一个View的实现类, 创建构造器和重写onDraw() 和onMesure()等方法. TypedArray获取自定义View的属性的数组 context.obtainStyledAttributes(attrs, R.styleable.MyView); // 从数组中根据styleable中定义的对应属性的值 属性是自定义View的名+“-”+属性名===>MyView_textColor int textColor = array.getColor(R.st

android应用Theme(一)

android切换Theme主流三种方式来切换Theme,第一种是通过内置的style来切换,一般用于夜间模式/日间模式切换.第二种是通过apk来实现插件化,第三种是通过下载zip进行解压到到相应的app文件下,应用讲需要文件读取到内存中.这篇是介绍第一种android切换Theme的方法. 首先当然是在values下面创建attrs文件,然后定义了一些attr. <?xml version="1.0" encoding="utf-8"?> <re

Android ProgressBar详解以及自定义

版本:1.0 日期:2014.5.16 版权:© 2014 kince 转载注明出处 这一次主要说一下Android下的进度条,为什么是它呢,因为近期被其各种美轮美奂的设计所倾倒,计划逐渐去实现.另外一个因素也是它也是为数不多的直接继承于View类的控件,从中可以学习到一些自定义控件的知识.下面列举了一些个人觉得还算漂亮的进度条,仅供参考. 是不是很漂亮,其实就像上面图形展示的那样,进度条大体上无非就是这几种形式.这样一来肯定是需要自定义了,所以方向有两个:要么继承于系统的ProgressBar

下拉刷新PullToRefresh定制

我们使用PullToRefresh库的时候,下拉的level-list以及刷新的帧动画都需要自己定制.如果每次都修改库非常麻烦,特别是一个项目有几个地方用到不同的样式,又不能多次关联同样的库.所以我们要自定义属性,在xml文件中就可以直接设置参数. 具体实现步骤: 1.在父类LoadingLayout中找到显示动画的ImageView控件,此控件自己定义,原来的控件隐藏. mLoadingImage = (ImageView) mInnerLayout.findViewById(R.id.img

Android初级教程初谈自定义view自定义属性

有些时候,自己要在布局文件中重复书写大量的代码来定义一个布局.这是最基本的使用,当然要掌握:但是有些场景都去对应的布局里面写对应的属性,就显得很无力.会发现,系统自带的控件无法满足我们的要求,这个时候就要考虑自定义控件.自定义view的世界,也很浩瀚,个人需要学的地方还有很多很多.自定义view,会节省开发效率,很有必要学习其基本原理和方法.接下来就对自定义view,做一个初步的认识,一步步了解封装的重要性.但是,也仅仅是一个初步,因为它实在太灵活了. 有这么一种场景,看图: 除了布局之外,还有