1 package org.mobiletrain.shudu08; 2 import android.content.Context; 3 import android.graphics.Canvas; 4 import android.graphics.Color; 5 import android.graphics.Paint; 6 import android.view.View; 7 8 9 public class MyView extends View{ 10 11 public MyView(Context context) { 12 super(context); 13 14 } 15 @Override 16 protected void onDraw(Canvas canvas) { 17 Paint paint = new Paint(); 18 //paint.setColor(Color.BLUE); 19 paint.setARGB(150, 0, 0, 200); 20 paint.setStrokeWidth(5); 21 paint.setStyle(Paint.Style.STROKE); 22 canvas.drawLine(0, 200, 600, 200, paint); 23 24 paint.setTextSize(100); 25 canvas.drawText("apple", 10, 200, paint); 26 paint.setStyle(Paint.Style.FILL); 27 canvas.drawText("apple", 300, 200, paint); 28 super.onDraw(canvas); 29 } 30 }
能看出drawText的y值就是基准线