Android自定義屬性,format詳解

2021-09-08 03:38:22 字數 2015 閱讀 3148

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

(1)屬性定義:

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:background = "@drawable/id"

2. color:顏色值。

(1)屬性定義:

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:textcolor = "#00ff00"

3. boolean:布林值。

(1)屬性定義:

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:focusable = "true"

4. dimension:尺寸值。

(1)屬性定義:

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

5. float:浮點值。

(1)屬性定義:

(2)屬性使用:

6. integer:整型值。

(1)屬性定義:

(2)屬性使用:

xmlns:android = ""  

android:drawable = "@drawable/id"  

android:pivotx = "50%"  

android:pivoty = "50%"  

android:framescount = "12"  

android:frameduration = "100"

7. string:字串。

(1)屬性定義:

(2)屬性使用:

8. fraction:百分數。

(1)屬性定義:

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

(2)屬性使用:

xmlns:android = ""

android:orientation = "vertical"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

>

10. flag:位或運算。

(1)屬性定義:

(2)屬性使用:

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

(1)屬性定義:

(2)屬性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

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

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...

android自定義屬性

建立自定義類myview android layout width wrap content android layout height wrap content sdj name abc sdj age 10 sdj color drawable bg shap 此時會報錯,因為缺少了sdj這個命...