Trying to make my item for listview. Here is the markup code

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="5dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@mipmap/ic_launcher" android:id="@+id/imgRadio" /> <TextView android:id="@+id/txtRadio" android:layout_width="match_parent" android:text="Радиостанция" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center_vertical"> </TextView> </LinearLayout> 

in the studio you can see normally, and in the virtual device, when I launch it, it is displayed quite differently:

enter image description here

it should be like that

enter image description here

    1 answer 1

    The picture was allowed to take place in accordance with the size. She took advantage of this opportunity. Either change the picture, or explicitly set its size (the second is preferable).

    • got it thank. - Sergey
    • The author of the answer, but what's better? adjustViewBounds or scaleType - Flippy
    • @ SergeyGrushin these constants about different things. adjustViewBounds will allow ImageView to take place in the measurement process with the same aspect ratio as the image inside. scaleType, on the other hand, is how to convert a picture for display inside the ImageView; it does not affect the size of the ImageView. For the described task, I would use exactly the specified dimensions in layout and scaleType with a centerCrop or centerInside value. - tse
    • @ SergeyGrushin if you can, then read how imageView works onMeasure (), much will become clearer. android.googlesource.com/platform/frameworks/base/+/refs/heads/… - tse
    • Yeah, ATP)) But see if I want to make the ImageView square, and the side of this square is unknown (calculated by weight) how to be? - Flippy