void addRoundRect(RectF rect, float[] radii, Path.Direction dir) //添加一个圆角区域
Path.Direction有两个值:效果如图
效果如图
效果如图
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.graphics.Paint.Style;
import android.graphics.Path;
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) {
canvas.drawColor(Color.WHITE);//指定画布的背景颜色为白色
Paint paint=new Paint();//创建一个采用默认设置的画笔
paint.setColor(Color.BLACK);//设置画笔颜色
paint.setAntiAlias(true);//使用抗锯齿功能
paint.setStyle(Style.STROKE);//设置填充方式为描边
//绘制圆形路径
Path pathCircle=new Path();
pathCircle.addCircle(70, 70, 40, Path.Direction.CCW);//添加逆时针的圆形路径
canvas.drawPath(pathCircle, paint);
//绘制折线路径
Path myPath=new Path();
myPath.moveTo(150,100);
myPath.lineTo(200,45);
myPath.lineTo(250,100);
myPath.lineTo(300,80);
canvas.drawPath(myPath, paint);
//绘制三角形路径
Path pathTr=new Path();
pathTr.moveTo(350,80);
pathTr.lineTo(400,30);
pathTr.lineTo(450,80);
pathTr.close();
canvas.drawPath(pathTr, paint);
//绘制环绕型的文字
String str="风萧萧兮易水寒,壮士一去兮不复还";
Path path=new Path();
path.addCircle(550, 100, 48, Path.Direction.CW);//创建顺时针的圆形路径
paint.setStyle(Style.FILL);//设置画笔的填充方式
canvas.drawTextOnPath(str, path, 0, -18, paint);
super.onDraw(canvas);
}
}
}
画出的效果如图
转载请注明出处:http://blog.csdn.net/acmman/article/details/45307025