How to Draw TextView on Canvas in android..?
We have Canvas.DrawBitmap()
, Canvas.drawText()
. Do we have any Method in Canvas which takes TextView as a parameter or any other method to display TextView on Canvas?
Actually, I have a alphabet in TextView and I have to make drawing on that alphabet which is in canvas.
Please suggest anything....Thanks for your cooperation
Canvas API is a drawing framework that is provided in Android, with the help of which we can create custom shapes like rectangle, circle, and many more in our UI design. With the help of this API, we can draw any type of shape for our app. The drawing of the different shapes is done using Bitmap.
A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.
StaticLayout (similar to DynamicLayout and BoringLayout ) is used to layout and draw text on a canvas. It is commonly used for the following tasks: Measuring how big multiline text would be after being laid out.
You can't draw a Textview directly, but you can put it in a layout and draw the layout. Something like this:
LinearLayout layout = new LinearLayout(context); TextView textView = new TextView(context); textView.setVisibility(View.VISIBLE); textView.setText("Hello world"); layout.addView(textView); layout.measure(canvas.getWidth(), canvas.getHeight()); layout.layout(0, 0, canvas.getWidth(), canvas.getHeight()); // To place the text view somewhere specific: //canvas.translate(0, 0); layout.draw(canvas);
May be you need to use StaticLayout
. It can draw formatted text, manages word wrapping and so on. Have a look at http://developer.android.com/reference/android/text/StaticLayout.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With