为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的只有横竖各一条线啊

public class WuziqiPanel extends View {

private int mPanelWidth;

private float mLineHight;

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(0x44ff0000);

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 heighSize = MeasureSpec.getSize(heightMeasureSpec);

int heighMode = MeasureSpec.getMode(heightMeasureSpec);


int width = Math.min(widthSize, heighSize);


if (widthMode == MeasureSpec.UNSPECIFIED) {

width = heighSize;

} else if (heighMode == MeasureSpec.UNSPECIFIED) {

width = widthSize;

}

setMeasuredDimension(width, width);

}


@Override

protected void onSizeChanged(int w, int h, int oldw, int oldh) {

// TODO Auto-generated method stub

super.onSizeChanged(w, h, oldw, oldh);

mPanelWidth = w;

mLineHight = 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 = mLineHight;

for (int i = 0; i < MAX_LINE; i++) {

int startX = (int) (lineHeight / 2);

int endX = (int) (w - lineHeight / 2);


int y = (int) ((0.5 + i) * lineHeight);

canvas.drawLine(startX, y, endX, y, mPaint);

canvas.drawLine(y, startX, y, endX, mPaint);

}

}


}


正在回答

1 回答

不奇怪啊,因为你的onSizeChanged函数中的mLineHight是0.1啊,后面的当然画不出来

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android-五子连珠
  • 参与学习       39006    人
  • 解答问题       166    个

Android游戏开发-五子连珠,本教程通过UI与逻辑实现双人对战

进入课程

为什么我的只有横竖各一条线啊

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信