【发布时间】:2017-09-12 15:17:20
【问题描述】:
在活动恢复后不久将视图从GONE 设置为VISIBLE 时,ConstraintLayout 间歇性地无法正确布局:
<android.support.constraint.ConstraintLayout
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@id/text1"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
override fun onResume() {
super.onResume()
text1.text = ""
text1.visibility = View.GONE
text2.text = ""
text2.visibility = View.GONE
text1.postDelayed({
text1.text = "Hello"
text1.visibility = View.VISIBLE
text2.text = "World"
text2.visibility = View.VISIBLE
}, 100
)
}
检测TextView 类显示TextView 实例被正确测量,但在布局时它们的宽度设置为0。
我想知道 ConstraintLayout LinearSystem 是否是不确定的。是否存在迭代未定义迭代顺序的映射? (我在 Cassowary 上见过这个)
【问题讨论】:
-
您是否能够在不使用 kotlin 的项目中重现这一点?我做不到,但它可能是特定于设备的。
-
不,我没有尝试过没有 Kotlin。如果它与 Kotlin 语言有关,我会感到非常惊讶。你在这里尝试过这个项目吗? github.com/alexbirkett/ConstraintLayoutBug 在较慢的旧手机上重现似乎最容易。我在视频中使用了三星 Galaxy S3
-
我下载了它,但我没有安装 Android Studio 3 测试版。当然,我可以安装它或尝试让项目使用不同的 gradle 插件,但这足以让我不想打扰。另外,如果我更改了插件,然后我无法重现它,那真的有用吗?
标签: android android-layout kotlin android-view android-constraintlayout