Centering the TextView's text vertically in relation to its drawableLeft image
You want "gravity" note this is not to be confused with layout gravity, layout gravity moves the entire textview, while gravity moves the text within the text view.
<TextView
android:id="@+id/item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/icon"
android:gravity="center_vertical" />
In addition to setting the gravity, this can also help with alignment in some situations by reducing paddings on the top and bottom of the textview, which can be unequal:
android:includeFontPadding="false"
If you don't care about text accents, just try android:includeFontPadding="false"
.This will remove extra top and bottom padding of TextView
.
As to android:gravity="center_vertical"
, it has no effect on my code.