I’m implementing a custom View, and I need to draw some text in it. The text has to fit in a box (so I have to break it up and make it fit). Because of this, I thought I could use a TextView and draw it inside my custom View. Here’s what I’ve tried:
canvas.drawRoundRect(rect, eventRadius, eventRadius, eventBg);
canvas.save();
canvas.clipRect(rect);
TextView tv = new TextView(getContext());
tv.setText(e.getSummary());
tv.setTextColor(Color.BLACK);
tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
tv.layout(0, 0, (int) (rect.right - rect.left), (int) (rect.bottom - rect.top));
tv.draw(canvas);
canvas.restore();
However, nothing is showing up. I know rect is OK because the first drawRoundRect works fine. What am I missing? Is there a better way? Maybe I should extend ViewGroup instead? I’m not sure how that would work.
To do it without wrapping:
to do it with wrapping
http://developer.android.com/reference/android/text/StaticLayout.html