package com.example.test;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取布局文件中添加的帧布局管理器
FrameLayout ll=(FrameLayout)findViewById(R.id.frameLayout1);
//将自定义的MyView视图添加到帧布局
ll.addView(new MyView(this));
}
public class MyView extends View{
public MyView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
Paint paintText=new Paint();//创建一个采用默认设置的画笔
paintText.setColor(0xFFFF6600);//设置画笔颜色
paintText.setTextAlign(Align.LEFT);//设置文字左对齐
paintText.setTextSize(24);//设置文字大小
paintText.setAntiAlias(true);//使用抗锯齿功能
canvas.drawText("勇士,能否帮我去送信?", 520, 75, paintText);
float[] pos=new float[]{400,260,425,260,450,260,475,260,
363,290,388,290,413,290,438,290,463,290,488,290,513,290};
canvas.drawPosText("好的,我接受任务!", pos, paintText);
super.onDraw(canvas);
}
}
}
运行效果如图所示
转载请注明出处:http://blog.csdn.net/acmman/article/details/45306897