Sep 12 | 3:55 PM |
Mark M. | has entered the room |
Sep 12 | 3:55 PM |
Mark M. | turned on guest access |
Marek D. | has entered the room |
Marek D. |
Good Saturday :)
|
Mark M. |
hello, Marek!
|
Mark M. |
how can I help you today?
|
Marek D. |
I was building this layout for some kind of shop page
|
Marek D. |
I already asked about it but to refresh
|
Marek D. |
there is header image
|
Sep 12 | 4:00 PM |
Marek D. |
some info about the shop
|
Marek D. |
and what you can buy there
|
Marek D. |
image url is from room
|
Marek D. |
information is from one endpoint that is usually fast
|
Marek D. |
and products take longer time to generate so they come last
|
Marek D. |
the image is constrained to the height of the views below
|
Marek D. |
so initally the image takes 80% of the screen
|
Marek D. |
when info loads it's 70%
|
Marek D. |
and products may push the image to minimum saize about 30%
|
Marek D. |
and they scroll (view)
|
Marek D. |
I use animateLayoutChanges
|
Marek D. |
=true and I am pretty amazed this works
|
Marek D. |
except the image resizing does not look so good
|
Marek D. |
is centerCrop
|
Marek D. |
because the way we send images is per device in theory (we give width of the device and server generates url)
|
Sep 12 | 4:05 PM |
Marek D. |
so if the shop sells electronics, every device should get let's say a chip in the center
|
Marek D. |
so my question is
|
Marek D. |
can I do something about this image scaling
|
Marek D. |
and if I did not know about the animateLayout changes, how I could write my own animation to animate that data appearing
|
Mark M. |
how are you populating the ImageView? are you using Glide? Picasso? something else?
|
Marek D. |
Glide
|
Marek D. |
the room + glide is often the fastest
|
Mark M. |
OK, and are you just having Glide load the image once? or are you telling it to reload the image after the resize operation?
|
Marek D. |
no only once
|
Mark M. |
that means Glide is probably initially scaling the image to the ImageView's original size, and ImageView is scaling it thereafter as the ImageView gets smaller
|
Marek D. |
yes that's true
|
Mark M. |
can you describe a bit about "does not look so good"? what sorts of effects are you seeing?
|
Sep 12 | 4:10 PM |
Mark M. |
you could try telling Glide to re-populate the ImageView after a size change, which may improve the look of the image, but I can't guarantee it
|
Marek D. |
ok
|
Marek D. |
i am trying to revise it once again, what was the effect
|
Marek D. |
one thing is that this image first shows vertically, you have the important element in the center
|
Marek D. |
then you have it bit above
|
Marek D. |
and the 3rd phase is at the top
|
Marek D. |
but I guess that was the algorithm to keep it at the center
|
Marek D. |
but this could be perhaps smoother
|
Mark M. |
sorry, but I did not really understand any of that
|
Mark M. |
animations are not the sort of thing that a text chat is well-suited to help debug :-)
|
Marek D. |
yes
|
Marek D. |
well if you have cropCenter
|
Sep 12 | 4:15 PM |
Marek D. |
and you have that important element
|
Marek D. |
is well at the center
|
Marek D. |
if the image gets smaller height and is laid as a header
|
Marek D. |
then this element appears somewhere higher
|
Mark M. |
I infrequently use cropCenter, and I doubt I have ever dynamically changed the size of an ImageView using cropCenter
|
Mark M. |
if you are saying that after the resize, it is no longer cropping at the center... other than having Glide update the ImageView again, I'm not certain what you can do
|
Mark M. |
if you have Glide's caching enabled, this will not involve a second load of the image from your server
|
Marek D. |
I mean that was our goal to show that element always in relation to that shop
|
Marek D. |
so we cannot complain now is jumping like crazy
|
Marek D. |
teh other thing was that we had visible blink(s) between those states
|
Marek D. |
but I just recently moved animatedLayoutChanges to the style of root view
|
Marek D. |
so I think all the viewgroups started scaling
|
Marek D. |
and I don't see it anymore
|
Sep 12 | 4:20 PM |
Marek D. | |
Marek D. |
this is much simpler version of what I have now
|
Marek D. |
because layout got bit more complex so I think is laying out slowly
|
Mark M. |
well, your image aspect ratio is changing, which is why the effects of cropCenter appear to be changing
|
Mark M. |
rather, your ImageView aspect ratio is changing
|
Mark M. |
unless you have the ImageView maintain its aspect ratio as you reduce its height, you will have that effect
|
Mark M. |
if this is a ConstraintLayout, and if all of these images will have the same aspect ratio (e.g., 4:3), you could tell ConstraintLayout to keep the ImageView at that aspect ratio and let the height vary
|
Mark M. |
however, that will give you white bars on the sides, as the ImageView reduces both width and height when the height changes
|
Marek D. |
I should have take a picture with human
|
Marek D. |
because this effect is more visibile
|
Marek D. |
I mean if we don't do that cropCenter
|
Marek D. |
it would stop showing a face of the person
|
Sep 12 | 4:25 PM |
Mark M. |
that does not really change the nature of the problem, though
|
Mark M. |
if you want the image to appear to stay steady and just reduce in size, you need to reduce the height and width evenly, keeping the ImageView aspect ratio the same
|
Marek D. |
well certainly we don't want white bars anywhere
|
Marek D. |
I think the problem is that it looks as it jumps to the states
|
Mark M. |
then you will have to live with the fact that the portion of the image that you see will change, as the aspect ratio of the ImageView changes
|
Marek D. |
the image gets smaller, the adding to the layout below is animated
|
Marek D. |
but ImageView is not a viewgroup
|
Marek D. |
so it just shrinks to next state and effect is that I have starting picture bigger and ending picture smaller
|
Marek D. |
I think is visible in the video I made
|
Marek D. |
the adding of thos text has some animation
|
Sep 12 | 4:30 PM |
Marek D. |
but the ImageView just gets next state and resizes
|
Marek D. |
so what I would like to achieve is to get smooother change from height of 80% to 50%
|
Mark M. |
you could try using https://developer.android.com/training/transitions or https://developer.android.com/training/constrai... or animate a switch between ConstraintSets
|
Marek D. |
ok, I just found something like this
|
Marek D. | |
Marek D. |
the thing under the demo behaves nicely
|
Marek D. |
I mean this what I am seeing in github, not that I tried it
|
Marek D. |
but that would be effect we want to have
|
Marek D. | |
Marek D. |
is bit small but the face of the actress is always in the center
|
Mark M. |
I have never tried to animate a size change like this, and so I cannot tell you precisely how to do it
|
Marek D. |
ok!
|
Mark M. |
AFAIK, animateLayoutChanges applies a very simple approach to the animations, and it may not be designed for your specific scenario
|
Sep 12 | 4:35 PM |
Mark M. |
but, there are plenty of animation solutions out there, including the ones that I listed earlier, plus your library and others
|
Marek D. |
yes I found some, including those you posted above, they require some investigation
|
Marek D. |
this animateLayout changes blowed my mind
|
Marek D. |
is just one line of code and the effect is allright
|
Mark M. |
yes, but you also encountered its limitations
|
Mark M. |
MotionLayout is where Google is putting most of their animation efforts for View-based layouts
|
Marek D. |
well this works for ViewGroups and ImageView is not
|
Marek D. |
I will wrap it in the FrameLayout and see :D
|
Mark M. |
well, your TextViews are not ViewGroups either
|
Mark M. |
I assume, in that demo, that the ImageView and the TextViews are all in the same container
|
Sep 12 | 4:40 PM |
Mark M. |
so, I do not know if the issue is that animateLayoutChanges does not animate size changes, or if the problem is in when/how ImageView adjusts its centerCrop effect, or what
|
Marek D. |
CL, ImageView, NestedScrollView with LinearLayout (animateLayoutChanges), Buttons
|
Mark M. |
ah, OK
|
Marek D. |
so the textViews are added to LL and this is animated
|
Mark M. |
you might try dumping the LinearLayout, then
|
Mark M. |
actually, that won't help
|
Mark M. |
because of the NestedScrollView
|
Marek D. |
I thought NSV requires a single child
|
Marek D. |
yep
|
Mark M. |
I suppose you could try putting animateLayoutChanges on both the LinearLayout and the root ConstraintLayout
|
Mark M. |
right now, your ImageView is not inside a container that uses animateLayoutChanges
|
Marek D. |
no difference
|
Mark M. |
ah, well, it was worth a try
|
Mark M. |
but animateLayoutChanges animates changes in its own ViewGroup, not to widgets that happen to be elsewhere on the screen
|
Marek D. |
yes I perhaps only when views are added
|
Sep 12 | 4:45 PM |
Marek D. |
In my complex layout in real world I added only to the view that gets the products
|
Marek D. |
it was ok-ish
|
Marek D. |
but until I added it as a style to root view
|
Marek D. |
it was ok-ish, and now is almost perfect
|
Marek D. |
if it hadn't been for that image :)
|
Mark M. |
at this point, I am out of ideas
|
Marek D. |
thank you for your help
|
Mark M. |
sorry I did not have better answers for you!
|
Marek D. |
was nice to discuss
|
Sep 12 | 4:50 PM |
Marek D. | |
Marek D. |
different question
|
Marek D. |
this is called idiomatic kotlin
|
Mark M. |
I would phrase this page as being a bunch of tips about Kotlin operations
|
Mark M. |
here, "Idioms" != "Idiomatic"
|
Marek D. |
ah right
|
Mark M. |
IMHO, it is not a great name for the page
|
Mark M. |
that being said, the particular tip that you linked to is a pretty common pattern, though whether you compare with true or false would depend on your situation
|
Mark M. |
and if you are using null to indicate a third state, then you would probably use a when(value) {} to handle that
|
Marek D. |
ah that's might be more readable
|
Marek D. |
if (b ?: false) I would write this one
|
Mark M. |
the example you linked to is for cases where you want to treat null as being equivalent to one of the other states
|
Mark M. |
that should work as well, for cases where you want to treat null as false
|
Sep 12 | 4:55 PM |
Marek D. |
we had if (string?.isBlank() == true) and I think that would be equivalent to if (!string.isNullOrBlank())
|
Marek D. |
but that's negative if so two conditions to reverse
|
Marek D. |
sorry if (string?.isNotBlank()) was the left
|
Marek D. |
still I don't need to think about nullability of the string, is clearer to see to me
|
Marek D. |
but I guess that might be personal for everyone
|
Mark M. |
yeah, I'd have to play around with that in Klassbook or something to confirm the equivalency, but I agree that using isNullOrBlank() and functions that work on String? are easier to read
|
Marek D. |
oh we reached the end of the chat!
|
Sep 12 | 5:00 PM |
Marek D. |
thanks for your time
|
Mark M. |
you're welcome!
|
Mark M. |
have a pleasant day!
|
Marek D. | has left the room |
Mark M. | turned off guest access |