i have created a custom view but am facing difficulties in positioning at center of screen.
public class CurvedText extends View {
private static final String MY_TEXT = "Select A Mode";
private Path mArc;
private Paint mPaintText;
public CurvedText(Context context, AttributeSet attrs) {
super(context, attrs);
mArc = new Path();
RectF oval = new RectF(0,0,200,200);
mArc.addArc(oval, -45, 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, 10, mPaintText);
invalidate();
}
}
I know i can workaround using setting RectF coordinates but i want this text at center of screen. SO how can i dynamically get the coordinates of the center of the screen? or any other way to position it at the center of the screen.
Adding Declaration:
<com.pkg.CurvedText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
</com.pkg.CurvedText>