Android:自定义View 初步之旅随记(一)
来源:互联网 发布:ff14帅气女性捏脸数据 编辑:程序博客网 时间:2024/05/06 15:55
自定义View 初步之旅1)自定义MEditText1 MEditText extends EditText(ImageView)2 可以实现三个构造器: public MEditText(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle);// 在布局文件中 声明 加上主题 init(context, attrs); } public MEditText(Context context, AttributeSet attrs) { this(context, attrs, 0);// 在布局文件中 声明 } public MEditText(Context context) { this(context, null); // 在代码中 MEditText e=new MEditTExt(context); } 3 init 方法 获取布局文件的控件自定义属性 在此文件中声明:values/attrs.xml <declare-styleable name="NoteEdit"> <!-- 定义属性名称,这个就是用在layout中的 --> <!-- 代码获取这个属性应该这样获取: color=typedArray.getColor(R.styleable.NoteEdit_noteLineColor,ColorBlack); --> <attr name="noteLineColor" format="color"></attr> </declare-styleable> 在布局文件中: 加个命名空间: xmlns:app="http://schemas.android.com/apk/res/包名" <com.example.thousanphone_1506.widget.MEditText app:noteLineColor="#5DA7F0" /> 在代码中获取自定义的属性: // 获取定义的属性集合,注意,obtainStyledAttributes 第一个参数是传递过来的属性集合// 第二个参数是在 attrs.xml 的<declare-styleable name="NoteEidt"> 的内容,这样再获取 TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.NoteEdit); if (typeArray != null) { defaultColor = typeArray.getColor( R.styleable.NoteEdit_noteLineColor, defaultColor); } 4 onDraw(Canvas canvas) canvas.drawLine(rect.left, currentY, rect.right, currentY, paint);2)Paint:颜料两个需要注意点:holds the style and color,how to draw geometries(几何图形), text(文本) and bitmaps(图片).3)Canvas4)Rect
1 0
- Android:自定义View 初步之旅随记(一)
- Android:Fragment 初步之旅 随记一
- Android自定义View初步(一)
- Android 进阶之路 自定义View(一)——初步尝试
- Android 自定义 View初步
- android自定义view之地图(一)
- Android进阶之自定义view(一)
- 【Android进阶之自定义View(一)】
- android 自定义view之概述(一)
- android 自定义view之(一) Creating a View Class
- Android开发之自定义View专题(一):自定义柱形图
- Android自定义控件之自定义View(一)
- android-自定义View初步探索
- Android中初步自定义view
- Android 自定义View(一)
- android-自定义View(一)
- android 自定义view(一)
- Android:自定义View(一)
- Expected identifier or '(' Unknown type name 'NSString'
- Java基础学习总结(32)——Java项目命名规范
- ubuntu14.04下配置opencv报错处理方法
- glViewport()函数和glOrtho()函数的理解(转)
- List和Tuple类型
- Android:自定义View 初步之旅随记(一)
- JAVA数组初始化及应用
- 第十四周实践项目1--验证折半查找
- 第三十四课——循环累加
- SpringMVC DWR 注解
- 机器学习(Machine Learning)心得体会(4)神经网络Exercise 4:Neural Networks
- 点击图片中的某个部分来跳转页面
- Gridview网格视图
- Web前端国际化之jQuery.i18n.properties