How can I get an ImageButton
that has a fixed height and is only as wide as it needs according to the ratio of its source image?
I tried the following:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="8pt"
android:minWidth="0pt"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="@drawable/list_download"
android:background="@android:color/black"
android:padding="0pt"/>
I set background to black just to see the boundaries of it exactly, and here is the outcome.
I have seen some solutions that suggest to use negative paddings but it is not an elegant solution. There should be a better one.
I tried similar configurations on an ImageView
too, but it also had extra padding. So it's not an ImageButton
specific problem (i.e. it is not related to this nine-patch issue).
EDIT: If I change scaleType
from fitCenter
to fitStart
, then the outcome is like this. So there is somehow a minimum width.