引用library之——帶有自訂屬性的自訂控制項的library包,library控制項

來源:互聯網
上載者:User

引用library之——帶有自訂屬性的自訂控制項的library包,library控制項

一般來講,當自訂一個控制項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"

123456789101112131415161718 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<span style="color: #339966;">//Panel所在的包名</span>    <span style="color: #ff6600;">xmlns:panel="http://schemas.android.com/apk/res-auto</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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.