Android面试中自定义ViewGroup的默认值为onDraw=0的问题及解决方案
发布时间
阅读量:
阅读量
问题
在开发过程中,当我们需要创建自定义视图时,通常需要对onDraw()方法进行覆盖处理,具体实现方式如下所示:
public class MyView extends View {
private Paint paint;
private Rect rect;
private Bitmap bitmap;
private Matrix matrix;
public MyView(Context context) {
super(context);
init();
}
public MyView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);
rect = new Rect(0,
全部评论 (0)
还没有任何评论哟~
