Office Hours — Today, August 29

Thursday, August 27

Aug 29
3:50 PM
Mark M.
has entered the room
3:55 PM
Mark M.
turned on guest access
marekdef
has entered the room
Mark M.
hello, marekdef!
how can I help you today?
marekdef
hi Mark
I have an image on the top and the bunch of information below
4:00 PM
marekdef
the number of information is varying
so there can be pages that have lot of information
and some that have almost none
what we would like to have is something like collapsing toolbar with image
but for the pages with little information we would like the image to stretch and have no scrolling
if I use coordinator I think I need to give the image size
Mark M.
you may wind up having to choose between two different layouts, based on whatever your cutoff is between "normal" and "no scrolling" interfaces
note that I have never implementing a collapsing toolbar, so I don't know much about how that works
marekdef
well I just started with it so maybe we can have that behaviro
4:05 PM
Mark M.
in general, if the UI in Scenario A is significantly different than the UI in Scenario B, trying to implement that using a single layout resource can be nasty
marekdef
yes but I am not sure how can I determine which layout to pick
we have title(s), some tags + dynamic number of buttons
in theory I could measure them
Mark M.
does each piece of information have titles+tags+buttons? or is the information itself titles+tags+buttons?
marekdef
the latter
I said titles but is one title but it can be wrapped to two lines
Mark M.
so, could the algorithm be as simple as "if the combined number of titles, tags, and buttons is less than N, use the no-scrolling UI"?
basically, some human is deciding that there is a no-scrolling UI scenario
that person also has the responsibility of deciding *when* you use the no-scrolling scenario
4:10 PM
Mark M.
perhaps with some negotiation with you and other engineers, to choose something that isn't crazy to implement :-)
for example, while the measuring solution probably could work, that seems like it is more work that should be needed to make this decision
marekdef
I always steer clear of code solutions for UI and look for layout that could work
I said no scrolling but this means more no collapsing
because with Coordinator + collapsing toolbar I seem to always be able to scroll the content up and collapse toolbar
Mark M.
yeah, unfortunately, since I don't have experience with collapsing toolbars, I do not know much about how to control whether collapsing is an option or not
marekdef
if there is no much information like the title only + button the view looks bit empty
Mark M.
fill the empty space with a picture of a kitten -- everyone loves kittens! :-)
marekdef
yes I want to have the image but on top :)
I have implemented some other option
Mark M.
have *two* images! the real one with an extra *bonus* kitten!
sudokai
has entered the room
4:15 PM
marekdef
so I have image + scroll view
sudokai
Hello Mark
marekdef
scroll view is wrap_content
Mark M.
(hello, sudokai: I will be with you shortly!)
marekdef
is constrained to a guideline somewhere on top + bottom + 1.0 bias (so is at the bottom always)
image is parent on top + the scroll
on the bottom
this works until scroll view exceeds the top constraint
and it seems is not holding to that constraint when has wrap content
Mark M.
if you have constraints like that, can the height be 0dp instead of wrap content?
marekdef
I. think then I will have it push the image to be smaller
Mark M.
the guideline is fixed -- 0dp should not move it
marekdef
the image is constrained to the scroll
that if scroll is small the image is big
the scroll is constrained to the guideline on the top
Mark M.
but then the image could be constrained to that guideline on the bottom
4:20 PM
marekdef
I don't have one, but I wanted the image to take the space this scroll cannot take
Mark M.
oh, yeah, OK, that's going to be a challenge
marekdef
OK
Mark M.
off the top of my head, I am not certain how you are going to be able to pull that off, though I certainly cannot rule out there being a solution
let me take a question from sudokai, and I will come back to you in a little bit
marekdef
sure!
Mark M.
sudokai: your turn! how can I help you today?
sudokai: do you have a question?
4:25 PM
Mark M.
sudokai: if you come up with a question, chime in!
in the meantime...
marekdef: back to you!
marekdef
I am wondering, if I have wrap_content + constraints, it seems if the view grows too much it does not respect the constraints
constraints = top + bottom
Mark M.
that may be more of a ScrollView thing -- have you tried NestedScrollView?
marekdef
actually I have NestedScrollView
Mark M.
ah
usually, with either of those, wrap_content for the height is the wrong answer
you want to say "this is the space in which you can scroll", which implies a fixed height or fixed top/bottom anchores
er, anchors
4:30 PM
Mark M.
instead of a top constraint, have you tried playing with wrap_content for the height, but also defining android:maxHeight?
4:30 PM
Mark M.
you aren't going to be able to set that dynamically in the layout (unless perhaps you are using data binding), but it may be worth an experiment to see if NestedScrollView behaves more as you would like with that setup
marekdef
android:maxHeight -> I used constrain version
app:layout_constraintHeight_max
this work almost :)
Mark M.
oh, right, the framework only has minHeight
marekdef
I think there is maxheight as well
Mark M.
not on View, at least according to the docs
marekdef
allright
this works but I would prefer to be constraining to the guideline
because with wrap + 1.0 bias this info component is measured from the bottom
so I give max height like 480dp it does not exactly hit the guideline
Mark M.
does that matter, though? your objective seems to be: have the actual NestedScrollView height be the maximum of the height of its content or a fixed value
4:35 PM
Mark M.
does it matter whether that fixed value comes from a guideline?
marekdef
well the spec specifies the minimum header size
so that is from the top
Mark M.
I guess that I do not understand how that impacts setting the max height of the NestedScrollView
marekdef
does not impact it and is hard to match them
Mark M.
¯\_(ツ)_/¯
marekdef
if I place the guideline at 200dp from the top
and the info is 480dp layout_constraintHeight_max
it works only on 680dp height I think
4:40 PM
sudokai
has left the room
Mark M.
I thought that your image was tied to the top of the NestedScrollView, though, not a guideline
marekdef
yes
Mark M.
so, what is the guideline for?
(in this scenario, where you are using layout_constraintHeight_max)
marekdef
yes in that scenario is
the guidelin is for the top of nested scroll view
or maybe it does not matter so much because this constraint apparently is not used
I would like it to be used
Mark M.
I am pretty much out of ideas at this point -- it is the sort of thing I would need to be playing around with layouts and stuff directly
marekdef
yes I understand
4:45 PM
marekdef
is there a way to make scroll view don't stretch my layout if is getting big
Mark M.
well, normally, a ScrollView/NestedScrollView does not stretch in the first place
normally, we give it a fixed height or fixed top/bottom anchors, so it knows its area to scroll inside
so, for example, as we discussed, if you use your guideline as the top anchor for the NestedScrollView, and you set the height to 0dp, the NestedScrollView should behave just fine... but you will not be able to have your ImageView "absorb" any excess space not needed by the NestedScrollView's contents
4:50 PM
Mark M.
that is why I was hoping that the max-height approach would be enough for your needs, as that is the only way that I can see where you can use wrap_content for the NestedScrollView (so you can have the ImageView take extra space when available) yet cap the height of the NestedScrollView (so it actually starts scrolling)
the only other idea I have is if you can write a custom RecyclerView LayoutManager that can implement your rules, and everything (ImageView and information) winds up in the RecyclerView
but I have never written a LayoutManager, let alone one like that
4:55 PM
marekdef
ok thank you
Mark M.
sorry that I did not have a better solution!
5:00 PM
marekdef
no problem at all
Mark M.
that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
and the next chat is Tuesday at 7:30pm US Eastern
have a pleasant day!
marekdef
has left the room
Mark M.
turned off guest access

Thursday, August 27

 

Office Hours

People in this transcript

  • marekdef
  • Mark Murphy
  • sudokai