I'm trying to place in single row the EditText
with the ImageView
on the left. But I can't get the image to be scaled properly to match the height of text entry.
The layout is simple:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:background="#f00"
android:src="@drawable/icon" />
<EditText
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
(I highlighted image background by red color to see the actual space allocated by ImageView)
If I specify the exact height for ImageView
:
android:layout_height="48dp"
then I get the closest view what I needed:
But I do not know the exact height of EditText
, so I can't specify it for ImageView
here.
When the height for ImageView
is specified to fill its parent (to match ``EditText` height):
android:layout_height="fill_parent"
then I get unexpected extra margin between the image and text entry:
Actually, in this case the ImageView
width equals to unscaled image width, whereas the image was scaled.
It's the similar to picture shown below if I specify layout_height
to 48dp
and set adjustViewBounds
to false
:
android:layout_height="48dp"
android:adjustViewBounds="false"
So, the question here is: how to define the layout correctly to scale the image to match edit entry height and in the same time to have width of ImageView
to be shrunk to scaled image width ? In other words how to get rid this extra space off?