ConstraintLayout间歇性布局失败

时间:2017-09-12 15:17:20

标签: android android-layout kotlin android-view android-constraintlayout

在恢复活动后不久,当视图从ConstraintLayout设置为GONE时,

VISIBLE间歇性地无法正确布局:

<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
        )
    }

Full source code here

检测TextView类会显示TextView实例已正确测量,但布局时宽度设置为0。

我想知道ConstraintLayout LinearSystem是否是非确定性的。是否存在迭代在未定义迭代顺序的地图? (我和Cassowary见过这个)

2 个答案:

答案 0 :(得分:0)

我希望你在github page中的陈述:

  在恢复活动后不久,当视图从 GONE 设置为 VISIBLE 时,

ConstraintLayout 会间歇性地无法正确布局

我检查了你的项目,并将100毫秒更改为1000毫秒。 这是输出:

enter image description here

在我看来,您希望在执行textview.setVisibility(View.GONE)的那一刻,您希望视图不可见。这不是android的工作方式。您只是将事件发布到MessageQueue稍后将由Looper处理的事件,而这100毫秒还不足以让人眼看到这些变化发生。

答案 1 :(得分:0)

这是constraint-layout:1.1.0-beta2 https://issuetracker.google.com/issues/65613481

中修复的ConstraintLayout中的错误
相关问题