Search code examples
androidandroid-imageviewandroid-image

android showing text within a image


In project I need to show first text within the image (Q letter image) and second text below the Q letter as show in the picture. How can I place the text as shown in the image?

enter image description here

The Q icon image can be shown on map as like this: enter image description here


Solution

  • You can use a TextView and set its background property to your image.

    <TextView
        android:id="@+id/q_text
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/q_placeholder_text"
        android:background="@drawable/q_drawable" />
    

    Or even better, add both the ImageView and the TextView to a FrameLayout. (The TextView and ImageView order matters)

    <FrameLayout
         android:id="@+id/q_layout"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
    
         <ImageView
              android:id="@+id/q_image"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:src="@drawable/q_drawable />
         <TextView
              android:id="@+id/q_text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:text="@string/q_placeholder_text />
    
    </FrameLayout>