- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下代码制作一个转轮。
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
for (int i = 0; i < segmentColors.length; i ++)
{
drawDataSet(canvas, i);
}
canvas.drawCircle(getWidth()/2, getHeight()/2, getWidth() - getWidth()/2 - dpToPx(5), mTransparentCirclePaint);
}
protected void drawDataSet(Canvas canvas, int position)
{
int color = segmentColors[position];
float mainArcAngle = ((float) 360/ (float)segmentColors.length);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
if ( position%2 == 0)
paint.setColor(color);
else
paint.setColor(Color.parseColor("#009f2f"));
RectF rect = new RectF(0, 0, getWidth(), getWidth());
canvas.drawArc(rect, (mainArcAngle * position), mainArcAngle, true, paint);
TextPaint mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(Color.BLACK);
mTextPaint.setAntiAlias(true);
mTextPaint.setTypeface(Typeface.MONOSPACE);
mTextPaint.setTextAlign(Paint.Align.CENTER);
mTextPaint.setTextSize(18f);
Path path = new Path();
path.addArc(rect, (mainArcAngle * position), mainArcAngle);
//PathMeasure pm = new PathMeasure(path, false);
//DynamicLayout layout = new DynamicLayout(values[position], values[position], mTextPaint, (int) pm.getLength(), Layout.Alignment.ALIGN_CENTER, 1, 0, true);
//canvas.save();
//layout.draw(canvas);
//canvas.restore();
canvas.drawTextOnPath(values[position], path, 0 , getWidth() / 6 , mTextPaint );
}
写在圆弧内的文本由于间距小而有点压缩。我怎样才能让它多行或增加字母间距?
最佳答案
从 API 21 开始,您可以使用 Paint#setLetterSpacing(float)
:
Set the paint's letter-spacing for text. The default value is 0. The value is in 'EM' units. Typical values for slight expansion will be around 0.05. Negative values tighten text.
您也可以 see TextView#setLetterSpacing()
是如何实现的。
关于android - 将字母间距设置为 drawTextOnPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44243460/
我正在使用以下代码制作一个转轮。 @Override public void onDraw(Canvas canvas) { super.onDraw(canvas);
在 hardware accelerated 自定义 View 添加到 ScrollView 或 ListView 以下两个代码 fragment 产生相同的结果: (请暂时忽略最佳实践) @Over
我在下面有以下代码。 public class CompassActivity extends Activity { public class OuterCircle extends View
我正在尝试创建一个自定义 View ,它有一个矩形,并且在它的正上方和正下方有一些文本。到目前为止,我使用 drawTextOnPath 方法成功地在绘制的矩形上方获取文本。然而,应该在矩形下方的那个
我正在尝试使用图像和文本绘制自定义 View ,一切正常,只是我的文本应该从左到右开始,但它是从右到左倒置的。 我在这幅画中使用了路径,矩形 我的XML输入如下, with xml input as
我有一个函数可以使用 drawTextOnPath 在 Canvas 上绘制文本。我计算偏移量一切正常,但我想以特定方式绘制它。当前文本旋转偏移等于圆圈偏移。我想将文本旋转 90/45 度。但我想不通
canvas.DrawTextOnPath 似乎不适用于 Lollipop 设备。看看这里的区别。 (连结 10图片正确,但 Lollipop 显示不正确) 代码是一个简单的路径绘制。 // Path
我正在使用 drawTextOnPath() 在 Canvas 上显示一些文本,我需要知道所绘制文本的尺寸。我知道这对于由多条线段、曲线等组成的路径是不可行的,但我的路径是一条完全水平的线段。我正在使
我是 Android 新手,我编写了以下示例代码。 public class Circle extends View { Paint paint = new Paint(); Path
我在扩展 View 中设置了一些代码,这些代码设置了一些易于缩放的图形(类似于矢量)。 (我的比例设置为 0-1.0) 我注意到,当我将油漆填充设置为 FILL 时,路径上绘制的文本看起来是正确的,但
我正在使用我自己的 https://github.com/mdg-iitr/RotatingText 版本为了显示一个旋转的文本小部件。此 GitHub 中提供了一个视频,可让您查看动画。这个想法是设
我是一名优秀的程序员,十分优秀!