【发布时间】:2019-09-01 17:41:21
【问题描述】:
我正在使用implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1',并启用了数据绑定。
当我的观点
<ImageView
android:id="@+id/im_lightning"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/charging"
android:src="@drawable/ic_lightning"
android:visibility="@{batteryViewModel.liveData.charging ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="@id/tv_percent"
app:layout_constraintRight_toLeftOf="@id/tv_percent"
app:layout_constraintTop_toTopOf="@id/tv_percent"
app:layout_constraintVertical_bias="1.0" />
包裹在协调器布局周围,其可见性变化按预期发生。一旦我将它包装在 MotionLayout 中,可见性更改就不会像以前那样起作用。准确地说,视图在应有的时候是不可见的。它在触发事件后变为可见一秒钟,然后恢复为不可见。这是一个已知的错误吗?
需要时的代码:
协调器布局:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground">
<ImageView (same as above) />
</androidx.constraintlayout.widget.ConstraintLayout>
运动布局:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.MainActivity">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
app:layoutDescription="@xml/home_scene_0"
app:showPaths="true">
<ImageView (same as above) />
</androidx.constraintlayout.motion.widget.MotionLayout>
<data>
<import type="android.view.View" />
<variable
name="batteryViewModel"
type="rish.crearo.minimalphone.viewmodels.BatteryViewModel" />
</data>
</layout>
【问题讨论】:
-
@tim-castelijns 真正困扰我的是什么——以至于我不喜欢在这里发布问题——问题被标记为重复/离题 yada yada 没有解释或提供指向重复的问题。感谢您抽出宝贵时间来标记这个问题,但如果没有反馈,下次我在 StackOverflow 上发帖时,我将无法成为更好的提问者。另外,我又找了一遍,似乎在任何地方都找不到这个问题。
-
除了“请查看链接的问题”之外,不确定您期望得到什么样的反馈。这个问题还不错,没必要改进。运动布局控制其子项的可见性。似乎这里的问题与那里的问题相同,因此关闭。如果您告诉我链接问题中的答案对您不起作用,我会很乐意重新打开您的问题
-
@tim-castelijns 我很抱歉。在问题顶部的链接和底部标记为重复的链接之间,我错过了看到链接。我开枪了!链接的问题对我有用。
标签: android android-coordinatorlayout android-motionlayout