I have a button in ring shape and I want to add a text around a button. Specifically, I want the text as below.
Asked
Active
Viewed 1,124 times
0

user4292106
- 441
- 1
- 11
- 24
-
Canvas#drawTextOnPath – pskink Jun 13 '15 at 09:47
-
@pskink can be more specific please? – user4292106 Jun 13 '15 at 10:21
1 Answers
1
This is simple custom view that allows you to draw the text in a circular way.
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);}
} }
Example :
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GraphicsView(this));}
}

Kartheek
- 7,104
- 3
- 30
- 44
-
reference: http://stackoverflow.com/questions/13153201/how-to-show-circular-text-using-textview-in-android – Ahmad Sanie Jun 13 '15 at 10:00
-
ok this is helpful, but in my activity i have already the setContentView with xml for entire activity, and also I want the textview to be around a button. – user4292106 Jun 13 '15 at 10:19
-
is was just an sample you can place your xml layout in the setContentView – Kartheek Jun 13 '15 at 10:21
-
and how can I call the above class for a specific TextView? I mean that if I have three TextViews which I want to be as above, can I to this inside from xml? – user4292106 Jun 13 '15 at 10:30
-