扩充类ConstraintLayout时出错

aus*_*rge 17 android android-studio android-constraintlayout

我遇到Android Studio问题.我最近升级了我的SDK Manager以包含;

compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
Run Code Online (Sandbox Code Playgroud)

classpath是

 classpath 'com.android.tools.build:gradle:2.2.3'
Run Code Online (Sandbox Code Playgroud)

项目建设很好.Intellisense和文档工作正常.但是,当我尝试在手机上运行(调试)应用程序时,我收到此错误;

 Caused by: android.view.InflateException: Binary XML file line #2:
 Binary XML file line #2: Error inflating class ConstraintLayout
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                   at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:443)
                   at android.app.Activity.setContentView(Activity.java:2172)
Run Code Online (Sandbox Code Playgroud)

我已经同步了.我重新启动了Android Studio.我已经清理并重建了这个项目.

有想法该怎么解决这个吗?谢谢!

-edit- XML看起来像这样;

<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:id="@+id/PLAY_PARENT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/greenfelt2"
android:padding="0dp">
Run Code Online (Sandbox Code Playgroud)

arj*_*jun 28

你应该添加如下

<android.support.constraint.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:id="@+id/PLAY_PARENT"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/greenfelt2"
 android:padding="0dp">
Run Code Online (Sandbox Code Playgroud)

compile 'com.android.support.constraint:constraint-layout:1.0.2'

有关最新版本,请点击此处

  • 对于那些从android支持切换到androidx的用户,请记住将android.support.constraint.ConstraintLayout更改为androidx.constraintlayout.widget.ConstraintLayout。 (7认同)

zul*_*apa 6

我不知道这是否是 2 年半前的解决方案,但今天我遇到了类似的错误。在这里找到答案:Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx

基本上只有约束布局的 xml 标签应该重命名为这些 ->

androidx.constraintlayout.widget.ConstraintLayout


归档时间:

查看次数:

30490 次

最近记录:

6 年,1 月 前