An interface error occurred after the androidStudio3.5 project was transferred to Androidx, Error inflating class androidx.constraintlayout.ConstraintLayout

AndroidStudio3.5.2, because the project was converted to Androidx, there were many errors, one of which was that the interface could not be displayed normally in the design designer, and it was grayed out. The complete error is as follows: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
Obviously, the error lies in the layout file, but what is wrong?

<?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>

I found out later that this ConstraintLayout should be in the widget. Here, because of the automatic conversion, the level of the included files was wrong. The correct approach is as follows:
Add the widget package and put it in front of the Constraint. You can gradually search for the corresponding layout header. The API hierarchy of the file.

<?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>

Guess you like

Origin blog.csdn.net/poolooloo/article/details/105946098