android 用paint写字,请问有什么办法能设置 字间距吗
1个回答
展开全部
这个方法就可以,那个1.3f就是字间距,可以调节
public static void getText(Canvas canvas,String str,float x,float y){
final TextPaint paint1 = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paint1.setColor(Color.WHITE);
paint1.setAntiAlias(true);
paint1.setTextSize(23);
paint1.setTextAlign(Align.LEFT);
final StaticLayout layout = new StaticLayout(
str, paint1,
(int) (MySurfaceView.screenW * 0.8),
Layout.Alignment.ALIGN_NORMAL, 1.3f, 0, true);
// layout是默认画在Canvas的(0,0)点的,如果需要调整位置只能在draw之前移Canvas的起始坐标
canvas.translate(x, y);
layout.draw(canvas);
}
public static void getText(Canvas canvas,String str,float x,float y){
final TextPaint paint1 = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paint1.setColor(Color.WHITE);
paint1.setAntiAlias(true);
paint1.setTextSize(23);
paint1.setTextAlign(Align.LEFT);
final StaticLayout layout = new StaticLayout(
str, paint1,
(int) (MySurfaceView.screenW * 0.8),
Layout.Alignment.ALIGN_NORMAL, 1.3f, 0, true);
// layout是默认画在Canvas的(0,0)点的,如果需要调整位置只能在draw之前移Canvas的起始坐标
canvas.translate(x, y);
layout.draw(canvas);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询