This view is not constrained vertically 的解决办法

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


如果你觉得本文对你有帮助,麻烦动动手指顶一下,算是对本文的一个认可,如果文中有什么错误的地方,还望指正,转载请注明转自喻志强的博客 ,谢谢!

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XeonYu

码字不易,鼓励随意。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值