Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linear layout doesn't wrap content

Tags:

android

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:

Linear Layout

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?

like image 813
iknow Avatar asked Mar 14 '26 09:03

iknow


1 Answers

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

like image 106
iknow Avatar answered Mar 17 '26 01:03

iknow