【发布时间】:2017-06-14 18:21:48
【问题描述】:
我有一个自定义视图,它应该绘制一些底部对齐的文本。 文本大小应为视图高度的 50%。
我应该如何更改此代码才能正常工作?
@Override
protected void onDraw(Canvas canvas)
{
float h = getMeasuredHeight();
float textHeight = h*0.5f;
paint.setTextSize(textHeight);
String str = "Abcdefghijklm";
paint.getTextBounds(str, 0, str.length(), bounds);
float height = bounds.height();
float yPos = height;
canvas.drawText(str, 0, yPos, paint);
}
【问题讨论】:
标签: android android-canvas drawtext