I insert a picture in the ImageView, the picture sometimes changes. For some reason, with some pictures, indents appear somewhere above 20dp and as much from below, and with some pictures normally. Pictures come in different sizes. Indents appear exactly, these are not pictures with a white background above and below, there are pictures and indentation somewhere in 40dp.

After all, in theory, it should be filled to the width, and then the picture fits into the height.

<LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/snow"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView2"/> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:clickable="true" android:onClick="radioGroupInvisible" android:background="@drawable/selector_lateral_menu"> 

alt text

    2 answers 2

     layout_width="match_parent" android:saleType="fitCenter" android:adjustViewBounds="true" 

    The android: adjustViewBounds attribute will indicate that the size of the ImageView should be resized to fit the image.

    • @Alexey Illarionov thanks, it helped, I wonder why she doesn’t do it by default, because logically it should be so, the container adjusts to the image, if wrap_content is specified. - J Mas

    android: scaleType - type of stretching the image in the container. Plus, you can put the imageView over

     layout_width="match_parent" это растянет контейнер по всей ширине. 
    • @nekaneka did not help, added a screenshot, with different pictures, differently fills the height, - J Mas
    • @nekaneka and when I put android: scaleType = "fitStart" there is no space left above, but this empty space that was above moved down, i.e., the empty space below became twice as large - J Mas
    • Do you need a full container, no lanes? - Kota1921
    • @nekaneka with some pictures, the line "OPERATOR" is immediately below the picture without indents, so I need to avoid indents, but what are the bars you mean? - J Mas