android:MotionLayout子级的可见性更改 [英] android:visibility changes to children of MotionLayout

查看:992
本文介绍了android:MotionLayout子级的可见性更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在动作布局中缺少android:visibility更改。这是我的布局的简化版本。

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>

我有一个MotionScreen,可根据回收者视图设置过渡滑动,以减少HeaderBackground的高度并隐藏一些图像/文本视图(即折叠工具栏)。
但是,如果出现一些致命错误,我想在RecyclerView的顶部/前面显示CustomViewGroup1,但是将RecyclerView的可见性切换为不显示,而将CustomViewGroup1切换为可见,则不会显示CustomViewGroup1。

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.

我可以将CustomViewGroup组从MotionLayout中移出,并添加framelayout作为活动的根,并隐藏整个MotionLayout。但这并不理想,因为我必须复制工具栏和图标。所以我想这个问题是关于可见性的变化和可能的z排序的吗?

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?

我正在使用 androidx.constraintlayout:constraintlayout:2.0.0-beta2

推荐答案

原来这是我对MotionLayout的工作方式缺乏经验。默认情况下,MotionLayout控制其中所有视图的可见性。但是,您可以使用 app:visibilityMode = ignore 属性中定义视图来退出子视图< ConstraintSet>

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>

在我来说,< CustomViewGroup1> 看起来像这样。 ..

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.

感谢John Hoford在另一个频道中提供的建议。

Thanks to John Hoford for the advice in another channel.

这篇关于android:MotionLayout子级的可见性更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆