自定义组合控件

1.自定义View 一般继承相对布局或相对布局,必须是ViewGroup


2.实现父类的构造方法,一般需要在构造方法中,初始化自定义的布局文件


3.根据需求,定义方法,设置XXX


4.自定义属性


5.自定义命名空间


<Layout xmls:(自定义)=“http://schemas.android.com/apk/res/(包名)”

<Layout   xmlns:aze="http://schemas.android.com/apk/res-auto"

参考 android-sdk-macosx ▸ platforms ▸ android-16 ▸ data ▸ res ▸ values>attrs.xml


6.自定义属性,在res/values/attrs.xml

  <declare-styleable name="RelativeLayout">

        <attr name="gravity" />

        <!-- Indicates what view should not be affected by gravity. -->

        <attr name="ignoreGravity" format="reference" />

    </declare-styleable>

 

7.使用自定义的属性


    <com.bruce.mobilesafe.ui.SettingItemView

        aze:title="设置自动更新"

        aze:desc_on="自动更新已经开启"

        aze:desc_off="自动更新已经关闭"

        android:id="@+id/siv_update"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" >

    </com.bruce.mobilesafe.ui.SettingItemView>

8.设置属性

在布局文件中设置这个类 使用的是带有两个参数的构造方法

布局文件中的属性,被封装成为AttributeSet

带有3个参数的构造方法,有默认样式

一个参数的构造方法,,new 

attrs.getAttritubeValue(namespace,name);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值