Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity, padding

  • 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 is a Snap shot

enter image description here

enter image description 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.

In App Level Gridle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.abhishek.ondemandservice"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),     'proguard-rules.pro'
        }
    }
}

Application level Gride.

buildscript {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
        mavenCentral()
    }
}
like image 640
Abhishek Avatar asked Feb 10 '16 06:02

Abhishek


People also ask

What is the layout_width attribute in Android?

The Android layout_width attribute is used to define the basic width of a view element you have in your layout. The width can be specified in any valid dimension measure ( dp, in, mm, pt, sp, px) Or you can also use the special constant for the width: match_parent and wrap_content. Let’s see some examples of the layout_width attribute in action.

How do I include a layout in an Android view?

Another way to include a layout is to use ViewStub. It is a lightweight View that consumes no layout space until you explicitly inflate it, at which point, it includes a layout file defined by its android:layout attribute. For more information about using ViewStub, read Loading Views On Demand.

What is the use of layout_gravity in Android?

android:layout_gravity is used to set the position of an element in its parent (e.g. a child View inside a Layout ). android:gravity is used to set the position of content inside an element (e.g. a text inside a TextView ).

What is a layout resource in Android?

A layout resource defines the architecture for the UI in an Activity or a component of a UI. The filename will be used as the resource ID. Resource pointer to a View (or subclass) resource.


Video Answer


2 Answers

Just go to Tools->Android->Sync Project with Gradle Files

like image 105
Marius Gheorghe Avatar answered Oct 18 '22 01:10

Marius Gheorghe


The only thing that worked for me was cleaning the following folders:

c:\Users\<user>\.gradle\caches\
c:\Users\<user>\.AndroidStudio3.2\system\caches\

Android Studio will just redownload the libraries and caches them which will enable everything back to normal.

Source: https://stackoverflow.com/a/53053438/7515903

Credits: @alexuz

like image 51
Mohamed Akl Avatar answered Oct 17 '22 23:10

Mohamed Akl