Here is a simple layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/companyIcon"
android:layout_width="wrap_content"
android:layout_height="40dp" <!-- notice I've limited a height -->
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/companyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/companyIcon"
android:layout_marginLeft="3dp"
android:layout_centerVertical="true"
android:textStyle="bold"
android:textColor="#20526d" />
</RelativeLayout>
The height of an image I will set by setImageBitmap() is more that 40dp.
Using this layout I have an extra space between ImageView and TextView, where did it come from?

But after I wrap the ImageView with FrameLayout I don’t have this unnecessary extra space:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/image_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/companyIcon"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true" />
</FrameLayout>
<TextView
android:id="@+id/companyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image_container"
android:layout_marginLeft="3dp"
android:layout_centerVertical="true"
android:textStyle="bold"
android:textColor="#20526d" />
</RelativeLayout>
And the result:

Can you guys explain why shall I put ImageView into FrameLayout to have things as intended? Thank you very much.
Since the
android:layout_height="40dp"with aandroid:scaleType="fitStart", the image is getting scaled down (and to the left/start) to fit the height, so this “extra space” is actually the original width of the image, since yourandroid:layout_width="wrap_content". I recreated your layout with my own image that is larger than40dp. When you select theImageView, you can see that its bounds stretch to the image’s original width.To further prove this, if I set
android:scaleType="center", no fit is applied and you can see theImageView‘s original width.It appears that since your
FrameLayoutusesandroid:layout_width="wrap_content", it gets the correct scaled down width from yourImageViewafter it gets scaled due toandroid:adjustViewBounds="true". It is strange that theImageViewitself usesandroid:layout_width="wrap_content", but shows the original image’s width, and not the scaled width. My hunch is that the height and width ofImageViews get set before the scaling is applied, so theImageViewgets the original image’s width, but the parentFrameLayoutgets the scaled width of it’sImageViewchild after the scaling is applied. This may not be true, but it appears that way to me.However, you can solve the unscaled width issue (without using a
FrameLayout) by usingandroid:maxHeight="40dp"on theImageView. You can then setandroid:layout_height="wrap_content"so your images can be smaller than40dpif the image is smaller.