【问题标题】:Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity and other attribute in xml未知属性android:layout_width、layout_height、id、gravity、layout_gravity等xml中的属性
【发布时间】:2018-11-20 12:51:06
【问题描述】:
  • 在所有 android 标签上出现未知属性错误。
  • 在布局 XML 中, 自动建议未显示所有属性(如layout_widthlayout_heightorientation,方向和所有其他安卓 属性。)

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

  • 干净的构建和重建
  • 已删除.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>

【问题讨论】:

  • 给我们更多的背景信息。您正在使用什么布局/元素等。并非所有人都支持所有这些属性
  • Hi tnx for response。我正在使用约束布局,我的 xml 无法识别任何属性。
  • 你的 xml 中声明了 android 命名空间吗?xmlns:android="http://schemas.android.com/apk/res/android"
  • 你能分享你的Xml布局代码吗,可能命名空间有问题
  • @Benjamin 你能在你的问题中添加这个吗?

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


【解决方案1】:

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

这可以帮助你解决它。

【讨论】:

  • 降级targetSdk真的不是解决办法
  • @TimCastelijns 嗨,是的,这不是真正的解决方案,但它解决了我的问题。
  • @Benjamin 祝你好运,当你将 targetSdk 提高到 28 时再次修复它
  • @TimCastelijns 我知道这不是一个可靠的解决方案,但它可以帮助诊断问题到目前为止,我们知道我在 28.0.0 中没有这个问题,在其他版本中没有
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2016-05-20
    • 1970-01-01
    • 2018-09-07
    • 2019-03-13
    • 2019-05-03
    • 1970-01-01
    • 2022-08-24
    • 2012-06-05
    • 1970-01-01
    相关资源
    最近更新 更多