How to Draw TextView on Canvas in android..?

前端 未结 3 722
北海茫月
北海茫月 2020-12-09 08:34

How to Draw TextView on Canvas in android..?

We have Canvas.DrawBitmap(), Canvas.drawText(). Do we have any Method in Canvas which takes Te

相关标签:
3条回答
  • 2020-12-09 09:11

    You need to create a class which will extend Textview. After that override onDraw method. This method provides you to draw your textview tha way you like it

    0 讨论(0)
  • 2020-12-09 09:20

    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

    0 讨论(0)
  • 2020-12-09 09:29

    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);
    
    0 讨论(0)
提交回复
热议问题