說我有一個有效的自定義視圖,命名爲com.package.MyCustomView(MyCustomView擴展的LinearLayout或任何View)Android和自定義視圖和自定義XML屬性
我可以這樣
在活動佈局使用<com.package.MyCustomView
android:id="@+id/myView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
但我想有這樣的事情:
<com.package.MyCustomView
android:id="@+id/myView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
MyCustomView_attribute1="100"
MyCustomView_attribute2="fantastic"/>
我想象中的有效的Android XML屬性類似情況android:layout_width將關聯的value (match_parent, wrap_content)
設置爲父視圖對象的特定屬性(通過使用反射或其他..)。我也是知道的命名空間(該行:xmlns:android="http://schemas.android.com/apk/res/android"
)的存在..
在任何情況下,我想同一種東西 - 爲我定製了我的看法的自定義XML屬性...
這可能嗎?如果是 - 如何?請給一些細節
謝謝..我完全跳過該部分 – pulancheck1988