constraintlayout
constraintlayout copied to clipboard
Execute ignore child requestLayout after transition completed
My current MotionLayout
have many child view (each child view also have some child view) and state, and this visibility of them is base on hot flow so I need to set it programmatically.
Because, MotionLayout
ignore child requestLayout
during the transition, sometime some view visibility is incorrect when I update them during the transition.
Using motion:layoutDuringTransition="honorRequest"
solve the visibility problem but it cause performance problem. The transition become laggy after few time transition (maybe because I have many view in MotionLayout).
Therefore, I think about a solution to call requestLayout
after the onTransitionCompleted
. It's working, I tested with some specific view and it work well. However, after onTransitionCompleted
I don't know which view should call requestLayout
. I think call requestLayout
to all MotionLayout
children is not good.
So it would be great if I know some view that I need to call requestLayout
after onTransitionCompleted
There is no good way to know. If we know we could build it in.
Thank you for the feedback. After learning, I understand the current situation but still can not a good solution so I would like to ask for a suggestion.
I current built with MotionLayout
is like a youtube mini player, Main screen have many tabs so there is many views inside.
Many of them flexible width/heigh such as TextView, ImageView, RecyclerView...
I update views base on some flow so in some rare moment, some views will update during motion layout transition. If that view is wrap content, then it won' update.
Some ways I tried to fix the problem
-
layoutDuringTransition="hornorRequest"
. It make transition luggy - Fixed the size of all view in
MotionLayout
. I support Accessibility and multiple language so I can not fixed the size forTextView
. Also, forRecyclerView
, I think it's not possible - requestLayout after transition complete. If I call requestLayout only for
knownIds
in MotionLayout, only child views visibility update, deep child views withwrap_content
(eg: TextView) will not update. Therefore, to make sure everything up-to-date, I need to lookup to all MotionLayout child but it make the application slower when 2 transitions happened close to each other. - Wait until transition complete then update UI: It still possible to transition while I update UI
I think many applications will do asynchronous tasks then update UI base on data response. Therefore, it will possible to have chance to update UI (changing size) during the transition like my case. This problem rarely happened but I still hope for solution with make the view display correctly after transition complete with suitable performance.
Your problem is real. It is compounded by the fact that some views request layout more often than they need. How I would deal with the problem if I were you:
- First make sure that your motions change the size of as few items is possible. Some times we do not realize we are doing this and it matters. (internally if it is only a move Android sometimes just copies the pixels)
- Create and use a subclass of Motionlayout so that you can implement your own logic for which layout request get honored
- Consider whitelisting the view, the region, and position in the transition where you honor layout.
Based on any insights make a concreate feature request.