开发者社区 问答 正文

自定义的View铺满了整个屏幕,本来让它只显示内容大小,在xml中wrap_content无效

protected void onDraw(Canvas canvas) {
 // TODO Auto-generated method stub
    Paint mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setColor(Color.parseColor("#26ffffff"));
    mPaint.setStrokeWidth(3);
    canvas.drawCircle(80, 80, 80, mPaint);

    Paint arcPaint = new Paint();
    arcPaint.setAntiAlias(true);
    arcPaint.setStyle(Paint.Style.STROKE);
    arcPaint.setColor(Color.parseColor("#d08cc9"));
    arcPaint.setStrokeWidth(3);
    RectF mRectF = new RectF(0, 0, 160, 160);
    canvas.drawArc(mRectF, 0f, 90f, false, arcPaint);

    super.onDraw(canvas);

}   

展开
收起
爵霸 2016-06-16 10:05:22 2468 分享 版权
0 条回答
写回答
取消 提交回答