未知属性android:layout_width,layout_height,id,gravity,layout_gravity和xml中的其他属性

时间:2018-11-20 12:51:07

标签: android android-studio android-layout android-xml android-layoutparams

  • 在所有android标签上获取未知属性错误。
  • 在布局XML中, 自动建议功能不会显示所有属性(例如layout_widthlayout_heightorientation,方向和所有其他Android设备 属性。)

此处我为解决此问题所做的事情:

  
      
  • 清理构建并重建
  •   
  • 已删除的.idea
  •   
  • 文件无效的缓存/重新启动。.
  •   
  • 选项打开省电模式。
  •   

SDk是最新的。

我的xml布局:

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

2 个答案:

答案 0 :(得分:1)

就像您一样,我遇到了同样的问题,我做了您所做的所有事情,这是我的解决方案。 也许问题是您的targetSDKversion在gradle中。如果是28.0.0,则可以将其更改为27.1.1,并使用gradle文件同步项目。

这可以帮助您解决问题。

答案 1 :(得分:0)

更改您的应用模块build.gradle文件中的内容,例如,注释一行,然后 点击File,然后点击Sync Project with Gradle Files