I wanted to create a Linear Layout with images in it. I added pictures to it but it doesn't wrap height to content. Here is my code:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@drawable/ic_launcher_background" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@drawable/ic_launcher_background" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@drawable/ic_launcher_background" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@drawable/ic_launcher_background" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@drawable/ic_launcher_background" />
</LinearLayout>
And here is output:

As You can see above and below each image is free space. The picture is a square so it should be aligned to the top edge without any free space. What can I do to avoid this margin?
Thanks to @Iscle. To make it work I had to set adjustViewBounds="true" on every ImageView. Setting it on once doesn't show any effects. Every view in Linear Layout must have this property set on true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With