如何从XML设计曲线文本视图?

时间:2018-02-23 07:34:37

标签: android textview curve

我想在Android中设计一个弯曲的文本视图,图片如下所示。

enter image description here

1 个答案:

答案 0 :(得分:0)

这是使用画布和绘制文本并使您自定义textview的工作。

public class CustomView extends View{
private static final String MY_TEXT = "Hello World";
private Path mArc;

private Paint mPaintText;

public CustomView(Context context) {
    super(context);

    mArc = new Path();
    RectF oval = new RectF(50,100,200,250);;
    mArc.addArc(oval, -180, 200);
    mPaintText = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintText.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintText.setColor(Color.WHITE);
    mPaintText.setTextSize(20f);

}

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawTextOnPath(MY_TEXT, mArc, 0, 20, mPaintText);
    invalidate();
}

}