2013-01-16 59 views
0

说我有一个有效的自定义视图,命名为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属性...

这可能吗?如果是 - 如何?请给一些细节

回答

0

是的,你可以这样执行...它会工作

<com.example.application.Drawer 
     xmlns:my="http://schemas.android.com/apk/res/com.example.application" 
     android:id="@+id/drawer" 
     android:layout_width="301dp" 
     android:layout_height="wrap_content" 
     my:content="@+id/content" 
     my:handle="@+id/handle" > 

但有一件事是,你应该在SRC