glide icon indicating copy to clipboard operation
glide copied to clipboard

Seemingly redudant warning about `wrap_content`

Open TheBrokenRail opened this issue 2 years ago • 0 comments

Glide Version: 4.15.1

Integration libraries: Using OkHttp3

Device/Android Version: Galaxy S21 / Android 13

Issue details / Repro steps / Use case background:

I'm using Glide to display a banner image with dynamic height. I've set the ImageView to have a width of match_parent and a height of wrap_content. And it works perfectly: the image takes up the full width of the screen, while also having the correct height to maintain the image's aspect ratio. This image is in a RecyclerView.

The weird part is this warning: Glide treats LayoutParams.WRAP_CONTENT as a request for an image the size of this device's screen dimensions. If you want to load the original image and are ok with the corresponding memory cost and OOMs (depending on the input size), use override(Target.SIZE_ORIGINAL). Otherwise, use LayoutParams.MATCH_PARENT, set layout_width and layout_height to fixed dimension, or use .override() with fixed dimensions..

Considering the image is not taking up the entire height of the device, it is definitely not treating it as match_parent. And adding override(Target.SIZE_ORIGINAL) just makes the image have a bunch of empty space above and below it. The warning seems not only redundant (because it's working perfectly) but also incorrect because it's clearly using wrap_content correctly. In fact, explictly setting the ImageView to have a height of match_parent prevents it from showing up at all!

Glide load line / GlideModule (if any) / list Adapter code (if any):

        // Banner
        ImageView banner = root.findViewById(R.id.posts_banner);
        if (bannerUrl != null) {
            Glide.with(root.getContext())
                    .load(bannerUrl)
                    .into(banner);
            banner.setVisibility(View.VISIBLE);
        } else {
            banner.setVisibility(View.GONE);
            Glide.with(root.getContext()).clear(banner);
        }

Layout XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/posts_banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@null" />

    <com.thebrokenrail.combustible.widget.Sorter
        android:id="@+id/feed_sorter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

Stack trace / LogCat:

Glide treats LayoutParams.WRAP_CONTENT as a request for an image the size of this device's screen dimensions. If you want to load the original image and are ok with the corresponding memory cost and OOMs (depending on the input size), use override(Target.SIZE_ORIGINAL). Otherwise, use LayoutParams.MATCH_PARENT, set layout_width and layout_height to fixed dimension, or use .override() with fixed dimensions.

TheBrokenRail avatar Aug 07 '23 06:08 TheBrokenRail