Is it possible to override the TextView class so that the width and height of the element are equal to the original size of the background image?

(you want to keep the original dimensions of the image and place the text in its center)

  • one
    Use height and width in ImageWiew as wrap_content . And the text is centered with RelativeLayout - tim_taller

1 answer 1

And if you do this:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"/> </RelativeLayout>