如何修复“attribute app:constraintBottom_toBottomOf not found”错误?

23

我是一个Android新手。 我正在构建一个AR应用程序,现在我打算添加一个用户界面。 我试图添加一个约束布局到app:layout_constraintBottom_toBottomOf ="parent",但是我得到了错误,说这个约束不存在。

这是我的代码和错误信息:

code and error more of error

我在activity_ux.xml文件中添加的所有代码行都以“app”开头,例如app:layout_constraintBottom_toTopOf似乎不起作用,我只是在这里展示一个例子,以使调试更容易。

我尝试在网上搜索,其中一个解决方案是我应该在我的SDK工具中安装“ConstraintLayout for Android”和“Solver for ConstraintLayout”,但我已经安装了此软件包。

    <FrameLayout 
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          tools:context="com.google.ar.sceneform.Overlei.Overlei">

    <fragment android:name="com.google.ar.sceneform.ux.ArFragment"
          android:id="@+id/ux_fragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent" />

    <LinearLayout
          android:id="@+id/gallery_layout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          app:layout_constraintBottom_toBottomOf="parent"
  >

   </LinearLayout>

   </FrameLayout>

我希望这个功能可以正常工作,如果内置的函数(例如此函数)无法正常工作,我不知道该从哪里开始寻找问题所在。

4个回答

47

谢谢大家的建议。我已经通过添加这行代码来解决了错误。

implementation 'com.android.support.constraint:constraint-layout:1.1.3'

在我的build.gradle(module.app)文件的dependencies中添加

再次感谢你的所有帮助。


我添加了 implementation 'androidx.constraintlayout:constraintlayout:2.1.4',问题得到了解决。 - AmerllicA

3

您应该仅在 ConstraintLayout 中使用 app:layout_constraintBottom_toBottomOf。如果您要在 FrameLayout 中使用,则可以尝试在 LinearLayout 中使用 android:gravity = "bottom"


0
将您的FrameLayout包装在ConstraintLayout中,或将FrameLayout更改为ConstraintLayout。

0
在我正在开发的 Flutter 插件中,我遇到了相同的问题,通过在插件的 build gradle 中添加以下行作为依赖项来解决了问题:

implementation 'com.android.support.constraint:constraint-layout:2.0.4'


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接