自定义view

自定义View的属性

首先在res/values/  下建立一个attrs.xml , 在里面定义我们的属性和声明我们的整个样式。

<resources>
    <declare-styleable name="LevelView">
        <attr name="limitRadius" format="dimension" />
        <attr name="limitColor" format="color"/>
    </declare-styleable>
</resources>

Color:颜色

dimension:尺寸值

自定义类实现

1.两个构造函数

public class MyView extends View{

//实现两个构造函数

public MyView(Context context) {

  super(context);

}

//实现这个可在布局xml中使用

public MyView(Context context,AttributeSet attrs){

      super(context, attrs); 

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容