今天我要画一个Android机器人,开始。
一小时后
android.jpg代码
package com.hencoder.hencoderpracticedraw1;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by liwei on 2017/8/7.
*/
public class androidView extends View {
private Paint paint;
private Paint paintLine;
private Path path;
public androidView(Context context) {
super(context);
initview();
}
private void initview() {
paint = new Paint();
paint.setColor(Color.parseColor("#8FCE31"));
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paintLine = new Paint();
paintLine.setColor(Color.parseColor("#8FCE31"));
paintLine.setAntiAlias(true);
paintLine.setStrokeWidth(10);
paintLine.setStrokeCap(Paint.Cap.ROUND);
paintLine.setStyle(Paint.Style.FILL);
path = new Path();
}
public androidView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initview();
}
public androidView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initview();
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//脑袋
path.arcTo(100, 100, 400, 400, -10, -160, true);
path.addCircle(185, 182, 20, Path.Direction.CW);
path.addCircle(315, 182, 20, Path.Direction.CW);
canvas.drawPath(path, paint);
//天线
canvas.drawLine(210, 120, 170, 70, paintLine);
canvas.drawLine(290, 120, 330, 70, paintLine);
canvas.drawPoint(170, 70, paintLine);
canvas.drawPoint(330, 70, paintLine);
//肚子
canvas.drawRoundRect(100, 235, 400, 435, 20, 20, paint);
canvas.drawRect(100, 235, 400, 265, paint);
//腿
canvas.drawRoundRect(145, 400, 205, 505, 30, 30, paint);
canvas.drawRoundRect(295, 400, 355, 505, 30, 30, paint);
//胳膊
canvas.drawRoundRect(40, 230, 90, 390, 25, 25, paint);
canvas.drawRoundRect(410, 230, 460, 390, 25, 25, paint);
}
}
Over 或许廉价、容易得到的东西大都不会去珍惜吧。
四月.jpg
网友评论