我有以下代码将一些文本放在图像的顶部:
val paint = TextPaint(Paint.ANTI_ALIAS_FLAG)
paint.color = Color.WHITE
paint.textSize = 40f //* context.resources.displayMetrics.density
paint.typeface = Typeface.DEFAULT_BOLD
//paint.textAlign = Paint.Align.
paint.setShadowLayer(1f, 0f, 1f, Color.DKGRAY)
val teststr = "Hello World Hello World Hello World Hello World"
val canvas = Canvas(bitmap)
val textLayout = StaticLayout(teststr, paint, canvas.width ,Layout.Alignment.ALIGN_CENTER, 1f, 0f, false)
textLayout.draw(canvas)
但是,实际上,我希望文本位于图像的底部。如何将StaticLayout
与底部对齐Bitmap
,使文本出现在图像底部。