androidStudio3.5工程转Androidx之后出现界面错误Error inflating class androidx.constraintlayout.ConstraintLayout

AndroidStudio3.5.2,因为将工程转为Androidx,所以出现了很多的错误,其中有一条便是界面在design设计器里无法显示正常,灰色了,完整错误如下:android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
很明显,错误在于布局文件,但是错在哪?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.ConstraintLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ResultActivity">

</androidx.constraintlayout.ConstraintLayout>

后面发现是因为这个ConstraintLayout应该是widget里面的,这里因为自动转化,搞错了包含文件的层次,正确的做法,如下:
添加widget包,放在Constraint前面,大家可以逐步去搜一下对应的布局头文件的API层次结构。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ResultActivity">

</androidx.constraintlayout.widget.ConstraintLayout>

猜你喜欢

转载自blog.csdn.net/poolooloo/article/details/105946098
今日推荐