How to Show Circular Text using TextView in Android

Ris*_*wal 13 android textview android-layout

I want to show text with circular shape in my android application.I know it is done with custome textview but can some buddy give me proper code.I am also attaching image which type of look i want.

在此输入图像描述

And*_*ack 18

你可以尝试这个经过测试和完整工作的代码:

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new GraphicsView(this));
    }

    static public class GraphicsView extends View {
        private static final String QUOTE = "This is a curved text";
        private Path circle;
        private Paint cPaint;
        private Paint tPaint;

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

            int color = Color.argb(127, 255, 0, 255);

            circle = new Path();
            circle.addCircle(230, 350, 150, Direction.CW);

            cPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
            cPaint.setStyle(Paint.Style.STROKE);
            cPaint.setColor(Color.LTGRAY);
            cPaint.setStrokeWidth(3);

            setBackgroundResource(R.drawable.heart);

            tPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
            tPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            tPaint.setColor(Color.BLACK);
            tPaint.setTextSize(50);
        }
        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawTextOnPath(QUOTE, circle, 485, 20, tPaint);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

输出将是:

在此输入图像描述

希望这有帮助.


Sim*_*mon 6

创建自定义视图并覆盖onDraw.在onDraw中,创建一个路径并使用drawTextOnPath.像这样的东西.textToDraw是您要显示的文本.油漆是你想要的任何油漆.

@Override onDraw(Canvas canvas){
    Path path = new Path();
    path.addCircle(x, y, 200, Path.Direction.CW);
    canvas.drawTextOnPath(textToDraw, path, textX, textY, paint);
}
Run Code Online (Sandbox Code Playgroud)

http://developer.android.com/training/custom-views/index.html http://developer.android.com/reference/android/graphics/Canvas.html#drawTextOnPath(java.lang.String,android.graphics .Path,float,float,android.graphics.Paint)


Yah*_*r10 -11

您不需要进行自定义视图。找到正确的TypeFace,放入您的项目并设置为您的TextView

或者使用 Microsoft Office 艺术字并将图像复制到您的项目中

在此输入图像描述