EasyDemo*自定义控件三种实现方式小demo(on Github)

1.第一种方式:组合控件
              1>定义:即将一些小的控件组合起来形成一个新的控件,这些小的控件多是系统自带的控件, 
                  比如很多应用中普遍使用的标题栏控件
              2>思路:
    2.1>主布局中嵌套其他布局[截图如下]
                     <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical" >

    <com.demo.customviewclass.TitleView
        android:id="@+id/title_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </com.demo.customviewclass.TitleView>

     </LinearLayout>
                     2.2>TitleView类需继承相对布局,同时使用LayoutInflater.inflate()加载TitleView类所对应的布局
               3>完整源码: 点击打开链接

2.第二种方式:自绘控件
              1>定义:即自绘控件的内容都是自己绘制出来的,在View的onDraw()中完成绘制
      2>思路:
2.1>主布局中嵌套其他布局[代码如下]
                   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

       <com.wayne.customviewclass2.CounterView
        android:id="@+id/title_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       </com.wayne.customviewclass2.CounterView> 

  </LinearLayout>
                2.2>CounterView类继承View,复写View中的onDraw() 
             3>完整源码: 点击打开链接

3.第三种方式:继承View,进行扩展(未实现)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值