Adding text to ImageView in Android

后端 未结 9 1608
北荒
北荒 2020-12-02 16:44

I want to use an ImageView to show some message in a fancy way.

How do I add text to an ImageView?

相关标签:
9条回答
  • 2020-12-02 17:20

    Use drawalbeLeft/Right/Bottom/Top in TextView to render image at respective position.

            <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/image"    
            android:text="@strings/text" 
            />
    
    0 讨论(0)
  • 2020-12-02 17:25

    With a FrameLayout you can place a text on top of an image view, the frame layout holding both an imageView and a textView.

    If that's not enough and you want something more fancy like 'drawing' text, you need to draw text on a canvas - a sample is here: How to draw RTL text (Arabic) onto a Bitmap and have it ordered properly?

    0 讨论(0)
  • 2020-12-02 17:29

    You can use the TextView for the same purpose, But if you want to use the same with the ImageView then you have to create a class and extends the ImageView then use onDraw() method to paint the text on to the canvas. for more details visit to http://developer.android.com/reference/android/graphics/Canvas.html

    0 讨论(0)
提交回复
热议问题