Description
I have an ImageView with width="match_parent" to which an image of 6,000px x 6,000px is loaded through a URL with the Glide library.
Problem
I don't know why, as the title says, I can't get it to fill the entire width, despite the image that is loaded.
Extra data
Try images of other dimensions (eg 1900x1080) and they keep stretching to the same point, leaving the left and right borders empty.
I attached a picture of what it looks like
Attached the xml code of the image
<RelativeLayout
android:id="@+id/relative_img_materia"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/ayuda">
<ImageView
android:id="@+id/img_materia"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:contentDescription="@string/ayuda" />
</RelativeLayout>
I attach the Java code of the Glide library
Glide.with(info_clases.this).load("https://preview.redd.it/f2j745lex6311.png?width=960&crop=smart&auto=webp&s=b4b4bbe2f22d64fd25c21e4e7217c4bff0446510")
.placeholder(R.drawable.img_loading).error(R.drawable.img_error).into(img_materia);
Thank you for reading
In your
ImageView
you have definedandroid:layout_width="match_parent"
which is correct.but if it does not cover the entire width of your device, this is because the container of this
ImageView
has not definedandroid:layout_width="match_parent"
Update: Analyzing the url you provide there is something that is important to comment, the url has a property
&crop=smart
that apparently scales with respect to the height of the image:it is for that reason that when you add it to your
ImageView
it does not cover the entire width since otherwise it would lose its appearance.What you have to do is define your
ImageView
a scaleType, you can useandroid:scaleType="fitXY"
that scales the image on the X and Y coordinates.but this property can modify the appearance of the image:
The ideal would be to use
android:scaleType="centerCrop"
so that the image is not distorted and maintains its appearance but it is contained within theImageView
: