我正在使用以下代码。
public class MyView extends View {
public MyView (final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
}
public MyView (final Context context, final AttributeSet attrs) {
this(context, attrs, 0);
}
public MyView (final Context context) {
this(context, null, 0);
}
@Override
protected void onDraw(final Canvas canvas) {
final float scale = Math.min(getWidth(), getHeight());
canvas.scale(scale, scale);
canvas.translate((scale == getHeight()) ? ((getWidth() - scale) / 2) / scale : 0
, (scale == getWidth()) ? ((getHeight() - scale) / 2) / scale : 0);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.GREEN);
paint.setTextSize(0.5f);
paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
paint.setTextAlign(Paint.Align.CENTER);
//paint.setLinearText(true);
canvas.drawText("Low", 1f, 0f, paint);
}
}
此代码仅打印L
[第一个字符]而不是完整字符串,因此我搜索了Google并找到this答案。但是在我尝试这一点时,没有显示任何内容。任何帮助都会非常值得赞赏。
我正在使用Lollipop