-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
View sizes are hard. #2431
Comments
See bumptech#2431 for details on what this does and why. This will introduce some behavior changes, especially if you’re not using fixed dimensions in your layout parameters.
@sjudd how does this address ConstraintLayout ? For the record in the XML often the sizes will be 0dp with constraints that will resolve the size at layout. Reading the logic it's not handled. And getting all the parents layout to find if there's a constraint layout does not seems good either. |
Thanks for reviewing and pointing that out @Tolriq. I've updated the steps a bit to better reflect what actually happens in the code. I will make one change though, which is to wait for at least one layout pass before using the screen dimensions for After that change I expect constraint layout will work. 0dp layout parameter and view sizes for As a fallback, there's also a new constructor argument for
Which reminds me that I need to pass that boolean through to ViewTarget subclasses. I'll make those changes shortly. |
In some cases wrap_content may be used as a default layout parameter, so we should at least wait for any pending layout passes before using it. Progress towards bumptech#2431.
Progress towards bumptech#2431.
Progress towards bumptech#2431.
V4.1 Logic
It's actually difficult to describe the logic in ViewTarget in Glide 4.1, but it's something like:
Target.SIZE_ORIGINAL
if no layout is currently requested and the layout params are set towrap_content
Where it works
This logic works for a couple of cases:
Where it breaks
It introduces two significant problems:
RecyclerView
/ListView
images may flash if the childViews
use thematch_parent
layout parameters because even if theViews
are re-used and have valid sizes that won't change, they're typically pending a layout when they're re-added to theRecyclerView
(if for no other reason than Glide callssetImageDrawable()
for the placeholder when the load is cleared and/or started).wrap_content
usesTarget.SIZE_ORIGINAL
, which causes OOMs.Where it doesn't work
It also doesn't solve one case that it was meant to solve:
3. The
View
uses fixed layout parameters, but the parent arbitrarily resizes the child ignoring the exact parameters.I've gone back and forth on this a few times, and the following seems clear:
vNext Logic
I believe I can improve on the v4.1 logic by:
wrap_content
and at least one layout pass has occurred, Log a warning suggesting to useTarget.SIZE_ORIGINAL
or some other fixed size viaoverride()
and use the screen dimensions.match_parent
, 0, orwrap_content
and no layout pass has occurred), wait for a layout pass, then go back to 1.As a result, there are a few things I expect not to work:
Views
inRecyclerView
where the layout parameters are set tomatch_parent
but where theLayoutManager
will set different parent sizes for different positions.wrap_content
and expecting an image that can be zoomed/panned.I can fix 1 by adding an option that will force a request to wait for layout if it's loaded into a View. I think 2 is mostly fixed by a warning log that suggests
SIZE_ORIGINAL
or another fixed layout parameter.The text was updated successfully, but these errors were encountered: