zoukankan      html  css  js  c++  java
  • 引用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"

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    //Panel所在的包名
        xmlns:panel="http://schemas.android.com/apk/res-auto"
        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>
    

      

  • 相关阅读:
    第一部分 类的初始
    第一部分 数据内存存储、常预定义值类型、用户自定义值类型、预定义引用类型
    第一部分 变量、数据类型
    第一部分 程序结分析、控制台输入输出
    第一部分 代码组织概念,集成开发环境(IDE)
    第一部分 记事本搞定第一个C#程序和编译过程剖析
    jQuery函数
    leaflet入门(五)API翻译(下)
    leaflet入门(四)API翻译(上)
    禁止浏览器缓存js
  • 原文地址:https://www.cnblogs.com/Cherry-B/p/4571276.html
Copyright © 2011-2022 走看看