We want a bow
text like this.
We need to add a
new class, in that we use Canvas to draw it.
In xml file add
a LinearLayout to wherever you want.
<LinearLayout
android:id="@+id/l2"
android:layout_width="300dp"
android:layout_height="300dp"
android:orientation="vertical" >
</LinearLayout>
Declare a global
variable LinearLayout, LinearLayout v;
Put class draw
inside layout.
v = (LinearLayout)
findViewById(R.id.l2);
v.addView(new
bowtext( this));
Ignore the mark
errors.
Copy this lines
to above last bracket.
@SuppressLint("DrawAllocation")
public class bowtext extends View {
private Paint paint,paint2;
public bowtext(Context
context){
super(context);
paint=new Paint();
paint.setColor(Color.RED);
paint.setTextSize(30);
paint2=new Paint();
paint2.setColor(Color.RED);
paint2.setStyle(Style.STROKE);
paint2.setAntiAlias(true);
}
@Override
protected void onDraw(final Canvas canvas)
{
// TODO
Auto-generated method stub
super.onDraw(canvas);
Path
path = new Path();
path.addArc(new RectF(100, 50,
320, 250), 220, 190);
canvas.drawTextOnPath("Đây là
chữ cong", path, 0, 0, paint);
//canvas.drawCircle(210, 180,
90, paint2);
}
}
Run to see the
bow text.
To change the
bow level, edit number 250 in the line path.addArc(new
RectF(100, 50, 320, 250),
220, 190);
If want to add a
circle, remove comment at the line canvas.drawCircle(210,
180, 90, paint2);
If want to fill
color circle, comment line paint2.setStyle(Style.STROKE);
Let look at line
public vechu(Context context){
It name the same
with class vechu, it call contructor of this class, we
create two variables paint, paint2 inside it.
No comments:
Post a Comment