Android自定义View进阶《一》
2016-08-10 14:15
323 查看
楼主第一次写博客,写的不好请不要喷。本人自定义view在学校学的不是很好,所以花点时间学习一下。写个博客记录下来,哈哈。好了,废话不多说。
1.在xml布局加上你自定义的布局
2、就是你的自定义view的文件了 继承View 同时注意必须要实现里面的几个构造方法
3、就是在onDraw中绘制了楼主就只是画了个圆
重写onMesure 这个方法可写可不写 不过一般大部分都还是写的。
好了,第一篇就写到这里了,毕竟是第一次,请大家勿怪。
1.在xml布局加上你自定义的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.zs.androidview.MainActivity" > <com.zs.view.MyView android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
2、就是你的自定义view的文件了 继承View 同时注意必须要实现里面的几个构造方法
public MyView(Context context) { // TODO Auto-generated constructor stub this(context,null); } public MyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // TODO Auto-generated constructor stub } public MyView(Context context, AttributeSet attrs) { this(context,attrs,0); }
3、就是在onDraw中绘制了楼主就只是画了个圆
protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); Paint p=new Paint();//初始化画笔 p.setColor(Color.YELLOW);//给画笔设置颜色 //// cx:圆心的x坐标。 //// cy:圆心的y坐标。 //// radius:圆的半径。 //// paint:绘制时所使用的画笔。 // canvas.drawCircle(150, 150, 100, p);//画圆 }
重写onMesure 这个方法可写可不写 不过一般大部分都还是写的。
好了,第一篇就写到这里了,毕竟是第一次,请大家勿怪。
相关文章推荐
- Android高手进阶教程(三)之----Android 中自定义View的应用.
- Android高手进阶教程(二十七)之---基于ViewFlipper实现的自定义新手指引控件.
- Android高手进阶教程(三)之----Android 中自定义View的应用.
- Android 自定义View (二) 进阶
- Android高手进阶教程(三)之----Android 中自定义View的应用
- Android高手进阶教程(三)之----Android 中自定义View的应用.
- Android高手进阶教程(三)之----Android 中自定义View的应用
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- Android高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- Android 自定义View (二) 进阶
- Android高手进阶教程(三)之----Android 中自定义View的应用.
- Android高手进阶教程(三)之----Android 中自定义View的应用.
- Android高手进阶教程(二十七)之---基于ViewFlipper实现的自定义新手指引控件.
- Android高手进阶教程(三)之----Android 中自定义View的应用
- Android高手进阶教程(三)之----Android 中自定义View的应用
- Android高手进阶教程(二十七)之---基于ViewFlipper实现的自定义新手指引控件.
- Android高手进阶教程(三)之----Android 中自定义View的应用.
- Android高手进阶教程(二十七)之---基于ViewFlipper实现的自定义新手指引控件.
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)