0

I have a layout with a FrameLayout, in FrameLayout, there is 2 RelativeLayout. I include this layout to activity_main.xml by include tag.
activity_main.xml is a MotionLayout and this "include layout" is a child of MotionLayout.
I have define a ConstraintSet, inside this ConstraintSet, I have define Constraint for this "include layout" (width=match_parent, height=wrap_content, bottomToBottomOfParent).

In the code, I show/hide above RelativeLayout by condition then I use transitionToState to transition to above ConstraintSet. Most of time, it work well but sometime the above "include layout" is not displayed.

I put debug (with delay 2 second to make sure the view fully render) and I found that when "include layout" is not displayed, it's height is 0 but the child view height is > 0

parentView.layoutParams.height=-2, -2 <=> WRAP_CONTENT

Is there any possible case which can cause this issue happened?

Linh
  • 57,942
  • 23
  • 262
  • 279
  • 1
    have you tried calling `requestLayout` and forced it to remeasure itself? Also, you know `FrameLayout` isn't a great choice for more than 1 child right? – Shark Sep 17 '21 at 09:34
  • Thank @Shark, I will try `requestLayout` when this case happened to see what will appear. I don't know `FrameLayout` isn't a great choice for more than 1 child right because I don't use it offen, this FrameLayout code is write by another team member, I will research about it – Linh Sep 17 '21 at 09:49
  • basically, force `measure()` on your problematic views, try not to use FrameLayout for more than 1 children, and if there are *still* problems, attach a GlobalLayoutObserver in which you will do necassary things - when you get a callback from it, height of all views should be non-zero.. But generally, you want to avoid doing all of these things, because they're code smell. – Shark Sep 17 '21 at 10:43
  • Can you share your motion xml or at least relevant snippets? How many states/transitions are declared? I had an issue of some constraints not being updated when I had 3-state motion and transitioning programatically before. – Pawel Sep 20 '21 at 14:25
  • @Pawel :o I have 6-state and 6 transition, I do transitioning programatically too. sorry I can not share the code because it long and complex. how did you solve your constraints not being updated problem. I didn't have time to try the hoford answer because i'm busy with other task :( – Linh Sep 20 '21 at 14:38
  • I had something like `state 1 <-> start state <-> state 2` and needed to jump from 1 to 2 but it didn't account for changes that only happen between start and 1. I used `updateState(R.id.start, getConstraintSet(R.id.start))` before doing jump to reset constraints but I'm not sure if that's helpful if you're running an animation. Perhaps you have to include layout constraints in all of your states to ensure that transition generated by `transitionToState` will be able to determine how to transition it? – Pawel Sep 20 '21 at 14:55
  • @Pawel in my case, I define all animation view constraints in `ConstraintSet` (not xml layout). Actually, this problem just sometime happened (about 50%) so I think I have defined constraint correct. Maybe library problem because I just downgrade ConstraintLayout to lower version and I see that the problem rarely happened – Linh Sep 22 '21 at 08:14

2 Answers2

1

For the transition in play at that moment try adding

<Transition  ...   motion:layoutDuringTransition="honorRequest" \>
hoford
  • 4,918
  • 2
  • 19
  • 19
  • Thank you. Few day agos, I upgrade my phone to Android 12, I try to add `motion:layoutDuringTransition` to all of `Transition`, many view won't show after transition so I think it don't solve my problem. My phone after upgrade have may problem so today I factory reset it, then I use layoutDuringTransition and I don't see this problem happened. – Linh Sep 22 '21 at 08:22
  • Before this problem happened just sometime happened. After add `layoutDuringTransition="honorRequest"`, I tested with more than 20 times and don't see it happened, I'm waiting for other team member to test on other phone – Linh Sep 22 '21 at 08:25
0

Well, I think By default MotionLayout relaying out during animation. We can change by the flag transition

 <Transition     motion:layoutDuringTransition="honorRequest" \>

The layout is being resolved at every pass (which is slow) but might suit your needs. Another approach would be to use MotionLabel which was designed to do smooth scaling. as follows------->

Mitigate the scaling quantization with an attribute scaleFromTextSize

  <androidx.constraintlayout.utils.widget.MotionLabel
app:textPanX="0"
app:scaleFromTextSize="40sp"
android:textSize="90sp"/>
Laxmi kant
  • 128
  • 1
  • 11