码迷,mamicode.com
首页 > 其他好文 > 详细

自定义View

时间:2014-12-14 17:06:27      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   ar   color   sp   on   div   

bubuko.com,布布扣

 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值就是基准线

 

bubuko.com,布布扣

 

自定义View

标签:android   style   blog   http   ar   color   sp   on   div   

原文地址:http://www.cnblogs.com/hixin/p/4162635.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!