https://kotlinlang.org logo
#splitties
Title
# splitties
i

ispbox

08/18/2019, 4:43 PM
Is there any practice how to initialize bunch of properties for single view? It looks like that the order is important from performance and result perspectives. For example, isChecked property for ToggleButton adds some time for initialization, and moreover its position in initialization influences the result (if it is before `textOn`/`textOff`, then
text
property should be initialized, and if it is after - everything works without this extra property). Maybe the is some technique for initialization in one transaction, without intermediate UI invalidation?
For example, should I call
setCompoundDrawables
or
text
after all related properties (like
padding
,
isAllCaps
,
setTypeFace
) are set?
l

louiscad

08/18/2019, 5:07 PM
I don't think it matters much. Layout is not done at initialization time anyway, so many things are scheduled for the next layout pass.
i

ilyagulya

08/19/2019, 1:39 PM
UI invalidation != UI redraw. Your changes will not be applied immediately, but will be scheduled to the next UI thread tick. So do whatever you want in any order you want. It does not matter at all.
i

ispbox

08/19/2019, 6:29 PM
@ilyagulya There is at least one difference I've found: isChecked property for ToggleButton. It should be set after textOn/textOff is set. Otherwise toggle button is shown with default I/O labels instead of given ones.
i

ilyagulya

08/19/2019, 7:35 PM
@ispbox that’s widget-specific problem. My answer was about your first question. There’s no such thing as view initialization transaction. Android framework (mostly) designed to apply all changes on the next UI tick. Some widgets could behave differently, of course, but you need to deal with it on your own.
👍 1
2 Views