Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
711 views
in Technique[技术] by (71.8m points)

android:visibility changes to children of MotionLayout

I must be missing something with android:visibility changes within a motion layout. Here’s a simplified version of my layout.

<MotionLayout>
 <ImageView android:id="@+id/HeaderBackground" />
Bunch of image views, Text views that are constrainted to the HeaderBackground. 
<RecyclerView android:visibility="visible">
<EditText android:visibility="visible">
<CustomViewGroup1 android:visibility="gone">
</MotionLayout>

I have a motionScreen that sets a Transition onswipe based on the recycler view to reduce the height of the HeaderBackground and hide some of the images/text views (i.e a collasping toolbar). However, if there’s some fatal error, I want to show CustomViewGroup1 on top/infront of the RecyclerView but toggling the visibility of the RecyclerView to gone and CustomViewGroup1 to visible doesn’t make the CustomViewGroup1 show.

I could move the CustomViewGroup group out of the MotionLayout and add a framelayout as the root of the activity and hide the whole MotionLayout. But this is less than ideal as I’d have to copy of the toolbar bar and icons. So I guess the question is about visibility changes and potentially z ordering?

I'm using androidx.constraintlayout:constraintlayout:2.0.0-beta2

question from:https://stackoverflow.com/questions/57168071/androidvisibility-changes-to-children-of-motionlayout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Turns out this was my inexperience with how MotionLayout works. By default MotionLayout controls the visibility of all views within it. But you can opt out child views by using the app:visibilityMode="ignore" attribute and defining the view in the <ConstraintSet>

In my case <CustomViewGroup1> looks like this...

<Constraint
      android:id="@id/CustomViewGroup1"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/HeaderBackground"
      app:layout_constraintVertical_weight="1"
      app:visibilityMode="ignore" />

And this is defined the same in both collasped and expended ConstraintSets as I don't want it to move/animation when the recycler view is scrolled.

Thanks to John Hoford for the advice in another channel.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...