Search code examples
androidandroid-studioandroid-layoutandroid-xmlandroid-layoutparams

Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity and other attribute in xml


  • Getting Unknown attribute error on all android tag.
  • In layout XML, Auto suggestion is not showing all attributes (like layout_width, layout_height, orientation, orientation & all others android attributes.)

here Things i have done to resolve this issue:

  • Clean Build & Rebuild
  • Deleted .idea
  • file Invalidated Caches/Restart..
  • option Turn On Power Save Mode.

SDk is up to date.

my xml layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    tools:context=".MainActivity"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Solution

  • I had same problem just like you and I did all of things that you've done and here is my solution. maybe problem is your targetSDKversion in gradle. if it is 28.0.0 you can change it to 27.1.1 and sync your project with gradle files.

    this can help you to solve it.