Android中自定義屬性的格式詳解

2021-06-22 01:35:59 字數 2585 閱讀 2828

1. reference:參考某一資源id。

(1)屬性定義:

background" format = "reference" />

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:background = "@drawable/id"

/>

2. color:顏色值。

(1)屬性定義:

textcolor" format = "color" />

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:textcolor

= "#00ff00"

/>

3. boolean:布林值。

(1)屬性定義:

focusable" format = "boolean" />

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:focusable = "true"

/>

4. dimension:尺寸值。

(1)屬性定義:

layout_width" format = "dimension" />

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

/>

5. float:浮點值。

(1)屬性定義:

fromalpha" format = "float" />

toalpha" format = "float" />

(2)屬性使用:

fromalpha = "1.0"

android:toalpha = "0.7"

/>

6. integer:整型值。

(1)屬性定義:

frameduration" format="integer" />

framescount" format="integer" />

(2)屬性使用:

xmlns:android = ""  

android:drawable = "@drawable/id"  

android:pivotx = "50%"  

android:pivoty = "50%"  

android:framescount = "12"  

android:frameduration = "100"

/>

7. string:字串。

(1)屬性定義:

apikey" format = "string" />

(2)屬性使用:

apikey = "0jokq80od1jl9c6haja99ugxcris2cgjko_bc_g"

/>

8. fraction:百分數。

(1)屬性定義:

pivotx" format = "fraction" />

pivoty" format = "fraction" />

(2)屬性使用:

xmlns: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)屬性定義:

orientation">

(2)屬性使用:

xmlns:android = ""

android:orientation = "vertical"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

>

10. flag:位或運算。

(1)屬性定義:

windowsoftinputmode">

(2)屬性使用:

注意:屬性定義時可以指定多種型別值。

(1)屬性定義:

background" format = "reference|color" />

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:background = "@drawable/id|#00ff00"

/>

Android中自定義屬性

重點內容 1,在專案檔案res value下面建立乙個attr.xml檔案,該檔案中包含若干個attr集合,例如 2,其中乙個屬性format還可以指定其他的型別比如 reference 表示引用,參考某一資源 idstring 表示字串 color 表示顏色值 dimension 表示尺寸值 bo...

Android 自定義屬性

1 在values資料夾下新建xml檔案,命名為attrs.xml,在該檔案中新增你的自定義屬性,例如 2 在布局檔案中使用 首先要定義命名空間xmlns test 命名根據喜好可以隨便取,url中packagename為你專案的包名 具體使用 3 在自定義控制項中讀取 在使用了自定義的屬性後,會呼...

Android 自定義屬性

今天看看如何自定義屬性,先總結一下步驟 1.自定義乙個view 2.在values資料夾下新建attr.xml檔案,在裡面定義自己的屬性 3.在布局檔案中使用自定義的屬性,注意命名空間 4.在構造方法中獲取自定義的屬性 下面我們一步步來講解上面的步驟 1.寫出自己的類 public class cu...