This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint less…
项目迁移到AndroidX后,运行项目时发现androidx.constraintlayout.widget.ConstraintLayout布局中的子控件提示如下错误
此时运行项项目时会出现崩溃的现象
此时,你要检查一下ConstraintLayout中的约束条件是否完整
所谓的完整就是水平和垂直的约束都要有
比如之前的是这么写的,这个时候,TextView是有红线提示错误的。
<TextView
android:id="@+id/projectNameTv"
android:layout_width="wrap_content"
android:text="某某设施点"
android:textColor="@color/black"
android:textSize="@dimen/font_16"
app:layout_constraintTop_toTopOf="parent"
android:layout_height="wrap_content"/>
是因为我只添加了垂直方向的约束
app:layout_constraintTop_toTopOf="parent"
水平方向的约束没有添加,在AndroidX中就提示错误了。
那么把水平方向的约束也添加上就好了。
如下
<TextView
android:id="@+id/projectNameTv"
android:layout_width="wrap_content"
android:text="某某设施点"
android:textColor="@color/black"
android:textSize="@dimen/font_16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_height="wrap_content"/>
然后确保你依赖的版本是最新的稳定版,可在Maven中查询最新的稳定版
androidx.constraintlayout版本查询
目前最新的稳定版是1.1.3
新的测试版还是暂时不要用了,可能会出现意想不到的bug
如果你觉得本文对你有帮助,麻烦动动手指顶一下,算是对本文的一个认可,如果文中有什么错误的地方,还望指正,转载请注明转自喻志强的博客 ,谢谢!