Android Studio で ConstraintLayout を拡張するときにエラーが発生しました 質問する

Android Studio で ConstraintLayout を拡張するときにエラーが発生しました 質問する

Android Studio で問題が発生しています。最近、SDK マネージャーをアップグレードして以下を追加しました。

compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'

クラスパスは

 classpath 'com.android.tools.build:gradle:2.2.3'

プロジェクトは正常にビルドされます。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)

Gradle を同期しました。Android Studio を再起動しました。プロジェクトをクリーンアップして再構築しました。

これを修正する方法について何かアイデアはありますか? よろしくお願いします!

-編集- 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">

ベストアンサー1

以下のように追加してください

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

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

最新リリースについてはここ

詳細についてはこのプロジェクトをご覧くださいConstraintLayout の使用法

アップデート

Androidサポートから に切り替える場合はandroidxandroid.support.constraint.ConstraintLayoutに変更することを忘れないでくださいandroidx.constraintlayout.widget.ConstraintLayout

おすすめ記事