android - android:对 MotionLayout 子项的可见性更改
问题描述
我一定错过了 android:visibility 在动作布局中的变化。这是我的布局的简化版本。
<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,它基于回收器视图设置一个Transition onswipe,以降低HeaderBackground 的高度并隐藏一些图像/文本视图(即折叠工具栏)。但是,如果有一些致命错误,我想在 RecyclerView 的顶部/前面显示 CustomViewGroup1,但是将 RecyclerView 的可见性切换为消失并且将 CustomViewGroup1 切换为可见不会使 CustomViewGroup1 显示。
我可以将 CustomViewGroup 组移出 MotionLayout 并添加一个框架布局作为活动的根并隐藏整个 MotionLayout。但这不太理想,因为我必须复制工具栏和图标。所以我想问题是关于可见性变化和潜在的 z 排序?
我在用着androidx.constraintlayout:constraintlayout:2.0.0-beta2
解决方案
原来这是我对 MotionLayout 如何工作的缺乏经验。默认情况下,MotionLayout 控制其中所有视图的可见性。但是您可以通过使用app:visibilityMode="ignore"
属性并在<ConstraintSet>
在我的情况下<CustomViewGroup1>
看起来像这样......
<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" />
这在折叠和展开的 ConstraintSets 中定义相同,因为我不希望它在滚动回收器视图时移动/动画。
感谢 John Hoford 在另一个频道中提供的建议。
推荐阅读
- python - 添加自定义 sphinx 扩展,如 scipy.minimize
- javascript - Javascript 中的 UnhandledPromiseRejectionWarning 错误
- java - Java 正则表达式示例
- android - react native - 使用 PayPal v2/订单付款
- python - Django 管理员在 UserAdmin 中排除
- dynamics-crm - 有没有办法将 Dynamics CRM 中的字段设为一次性输入字段?
- database - 使用 nuxt 和个人后端 API 获取/访问数据信息的最佳方式是什么?
- gitlab - 社区版服务器的 Gitlab 分支命名保护
- spring - 如何在 Spring 中使用 REST 调用从另一个项目调用 @Service?
- javascript - 如何在纯 javascript 或 typescript 中访问表的最后一列