• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

线画不出来为什么?

public class WuziqiPanel extends View {    private int mPanelwidth;    private float mLineheight;    private int MAX_LINE = 10;    private Paint mPaint = new Paint();    public WuziqiPanel(Context context, AttributeSet attrs) {        super(context, attrs);        setBackgroundColor(0x44ff0000);        init();    }    private void init() {        mPaint.setColor(0x88000000);        mPaint.setAntiAlias(true);        mPaint.setDither(true);        mPaint.setStyle(Paint.Style.STROKE);    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        int widthSize = MeasureSpec.getSize(widthMeasureSpec);        int widthMode = MeasureSpec.getMode(widthMeasureSpec);        int heightSize = MeasureSpec.getSize(heightMeasureSpec);        int heightMode = MeasureSpec.getMode(heightMeasureSpec);        int width = Math.min(widthSize,heightSize);        if (widthMode==MeasureSpec.UNSPECIFIED){            width = heightSize;        }else if(heightMode==MeasureSpec.UNSPECIFIED){            width = widthSize;        }        setMeasuredDimension(width,width);    }    @Override    protected void onSizeChanged(int w, int h, int oldw, int oldh) {        super.onSizeChanged(w, h, oldw, oldh);        mPanelwidth = w;        mLineheight = mLineheight*1.0f/MAX_LINE;    }    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        drawBoard(canvas);    }    private void drawBoard(Canvas canvas) {        int w = mPanelwidth;        float lineHeight = mLineheight;        for(int i=0;i

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

2个问题,首先第一个你的代码没问题,线画出来了,在控件的顶上一条,左边一条,不太明显,因为在控件的边界上.
第2个问题你只重写了2个参数的构造器,也就是这个控件只能在xml布局里使用,代码new出来这个控件添加到界面上是没效果的,因为new控件走一个参数的构造器.
如果说你的代码有什么毛病,就是for循环里的代码了.你把for循环整个注释掉 替换成
canvas.drawLine(0,getHeight()/2,getWidth(),getHeight()/2,mPaint);

这句代码,就能比较明显的看见线了. 纯手打 给个采纳吧

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!