Android — Is it possible to warp a TextView?

2020-06-23 06:38发布

I'd like to warp a TextView with an arc shape. I know it's possible to warp images, but is it possible to warp TextViews? Is there a established pattern for doing so?

My other option is to warp the text in Photoshop, save it with a transparent background, and use an ImageView, but a client wants this done in about 10 places and I'd like to avoid the extra resources if I can.

warped text

2条回答
一夜七次
2楼-- · 2020-06-23 07:10

You need to use customView, override the onDraw(), create a path and use drawTextOnPath.

@Override onDraw(Canvas canvas){
    Path mPath = new Path();
    mPath.addCircle(x, y, 200, Path.Direction.CW);
    canvas.drawTextOnPath(textToDraw, mPath, textX, textY, paint);
}

Please have a look Draw text in circular view?

How to Show Circular Text using TextView in Android

查看更多
狗以群分
3楼-- · 2020-06-23 07:17

Views in Android are rectangular so you'll have to use Canvas and Paint to achieve your goal. Take a look at API Demos in the SDK samples. There is one entry called Graphics/Text Align which shows text drawn along a curving path.

查看更多
登录 后发表回答