一般來講,當自定義一個控件Panel並且此控件有自定義屬性時(例如:panel:closedHandle="@drawable/foot_bar_right"),xml中需要定義此控件的引用地址,(例如:xmlns:panel="http://schemas.android.com/apk/com.example.view")
這樣就可以在xml中引用自定義控件了。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" //Panel所在的包名 xmlns:panel="http://schemas.android.com/apk/com.example.view" android:layout_width="match_parent" android:layout_height="match_parent" > //自定義控件Panel <com.example.view.Panel android:id="@+id/panel" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_gravity="left" panel:closedHandle="@drawable/foot_bar_right" panel:content="@+id/panelContent" panel:handle="@+id/panelHandle" panel:openedHandle="@drawable/foot_bar_left" panel:position="left" > </com.example.view.Panel>
但是
當想要引用的自定義控件爲library時,並且此控件也具有自定義的屬性,如上(它在attrs.xml中有自定義屬性),此時在新項目中引用時,就不能在xml中引用包名。
而是引用:xmlns:panel="http://schemas.android.com/apk/res-auto"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<RelativeLayout
xmlns:android= "http://schemas.android.com/apk/res/android" <span
style= "color:
#339966;" > //Panel所在的包名</span> android:layout_width= "match_parent" android:layout_height= "match_parent" > <span
style= "color:
#339966;" > //自定義控件Panel</span> <com.example.view.Panel android:id= "@+id/panel" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:layout_alignParentBottom= "true" android:layout_gravity= "left" panel:closedHandle= "@drawable/foot_bar_right" panel:content= "@+id/panelContent" panel:handle= "@+id/panelHandle" panel:openedHandle= "@drawable/foot_bar_left" panel:position= "left" > </com.example.view.Panel> |