Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class V extends View {
- Path path;
- TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
- Layout layout;
- String source = "The silence of your volumes will appear extraordinarilly when you avoid that surrender is the seeker.";
- public V(Context context) {
- super(context);
- float size = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics());
- paint.setTextSize(size);
- paint.setColor(Color.WHITE);
- paint.setTextAlign(Paint.Align.CENTER);
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- path = new Path();
- float size = paint.getTextSize();
- path.moveTo(size, size);
- path.quadTo(w / 2, -size, w - size, size);
- PathMeasure pm = new PathMeasure(path, false);
- layout = new StaticLayout(source, paint, (int) pm.getLength(), Layout.Alignment.ALIGN_NORMAL, 1, 0, false);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- int numLines = layout.getLineCount();
- for (int i = 0; i < numLines; i++) {
- int start = layout.getLineStart(i);
- int end = layout.getLineEnd(i);
- canvas.save();
- canvas.translate(0, layout.getLineBaseline(i));
- canvas.drawTextOnPath(source.substring(start, end), path, 0, 0, paint);
- canvas.restore();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement