Center an image within a Textview

Asked

Viewed 118 times

0

How do I center an image inside a Textview? I used the attribute:

android:drawableStart="@drawable/email"

But the image is decentralized:

Imagem Descentralizada dentro de um TextView

In this case I can work with this image inside Textview or in this case it is better to use an Imagemview after a Textview ?

Thanks

  • I recommend you post the XML code so we can analyze it. I also recommend that you use the elements with the most logical content, in this case Textview with Text and Imageview with Images, because then you won’t have to do any tricks and you won’t have any problems.

1 answer

0

If this is not the solution please reply to the post with XML code.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/some_drawable"
    android:text="some text"
    android:layout_gravity="center"
    android:gravity="center"
    />

Try using the properties below to align the hint and image to the center, I did a quick test here and it worked perfectly.

android:layout_gravity="center"
android:gravity="center"

android:layout_gravity Gravity specifies how a Component should be placed in its group of Cells.

Gravity Gravity for the view Associated with These Layoutparams.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.