Android的xml文件中的@和?的区别
@大家已经司空见惯。比如@+id/... @string/...
看下面代码:
<declare-styleable name="ImageView"> <!-- Sets a drawable as the content of this ImageView. --> <attr name="src" format="reference|color" /> <!-- Controls how the image should be resized or moved to match the size of this ImageView. --> <attr name="scaleType"> <enum name="matrix" value="0" /> <enum name="fitXY" value="1" /> <enum name="fitStart" value="2" /> <enum name="fitCenter" value="3" /> <enum name="fitEnd" value="4" /> <enum name="center" value="5" /> <enum name="centerCrop" value="6" /> <enum name="centerInside" value="7" /> </attr> <!-- Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable. --> <attr name="adjustViewBounds" format="boolean" /> <!-- An optional argument to supply a maximum width for this view. See {see android.widget.ImageView#setMaxWidth} for details. --> <attr name="maxWidth" format="dimension" /> <!-- An optional argument to supply a maximum height for this view. See {see android.widget.ImageView#setMaxHeight} for details. --> <attr name="maxHeight" format="dimension" /> <!-- Set a tinting color for the image --> <attr name="tint" format="color" /> <!-- If true, the image view will be baseline aligned with based on its bottom edge --> <attr name="baselineAlignBottom" format="boolean" /> <!-- If true, the image will be cropped to fit within its padding --> <attr name="cropToPadding" format="boolean" /> </declare-styleable>
同样,Android系统也为Theme定义了很多属性(可以看看attrs.xml文件),其中每个主题属性的名称都一一对应D:\android-sdk\platforms\android-16\data\res\values目录下的themes.xml文件。当要用到主题属性的时候,就不需要特别指定android:attr/,可以直接在?后面加上属性名。