Canvas 对象作为 SeekBar 中的拇指,测试对齐。安卓
我在将文本的正确位置设置为画布对象中的绘画时遇到问题, 我在自定义 SeekBar 中将其用作拇指。
public BitmapDrawable writeOnDrawable(int drawableId, String text)
{
Bitmap bm = BitmapFactory.decodeResource(getResources(),drawableId).copy(Bitmap.Config.ARGB_8888, true);
bm.setDensity(165);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(size);
paint.setTypeface(my.b1);
paint.setTextAlign(Paint.Align.CENTER);
Canvas canvas = new Canvas(bm);
canvas.setDensity(165);
canvas.drawText(text, 0, bm.getHeight()/2, paint);
return new BitmapDrawable(bm);
}
有一个圆圈显示当前进度。所以文字是 动态原因可以是 2 个字符(“0-9%”)到 4 个字符(“100%”)。而且问题不仅仅在于位置, 还与文字的大小有关。
I have a problem with set up the right position of the text as a paint in canvas object,
which I use as thumb in customise SeekBar.
public BitmapDrawable writeOnDrawable(int drawableId, String text)
{
Bitmap bm = BitmapFactory.decodeResource(getResources(),drawableId).copy(Bitmap.Config.ARGB_8888, true);
bm.setDensity(165);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(size);
paint.setTypeface(my.b1);
paint.setTextAlign(Paint.Align.CENTER);
Canvas canvas = new Canvas(bm);
canvas.setDensity(165);
canvas.drawText(text, 0, bm.getHeight()/2, paint);
return new BitmapDrawable(bm);
}
There is a circle with current progress. So the text is
dynamic cause can be from 2 characters ("0-9%") to
4 characters ("100%"). Also the problem is not only with position,
but also with the size of the text.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论