【发布时间】:2013-01-16 18:42:14
【问题描述】:
假设我有一个有效的自定义视图,名为 com.package.MyCustomView(MyCustomView 扩展了 LinearLayout 或任何视图)
我可以在这样的活动布局中使用它
<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:layout_width 这样的有效 android xml 属性,关联的value (match_parent, wrap_content) 将设置在父 View 对象的特定属性上(通过使用反射或其他方式。 . ).我也知道命名空间的存在(那行:xmlns:android="http://schemas.android.com/apk/res/android")..
在任何情况下,我都想要相同类型的东西 - 为我的视图自定义自定义 xml 属性...
这可能吗?如果是 - 如何?请提供一些细节
【问题讨论】:
标签: android xml view custom-controls