【问题标题】:Android Constraint Layout showing attribute 'android:layout_constraintWidth_percent' not found未找到显示属性“android:layout_constraintWidth_percent”的 Android 约束布局
【发布时间】:2018-11-22 21:57:55
【问题描述】:

我为此错误进行了很多搜索,但最终看到每个人都建议卸载 android studio 并使用所有 sdk 工作重新安装它,这对我来说是不可行的。我们如何才能以体面的方式消除此错误,如果有人已经给出了正确的答案,请参考我的答案。

【问题讨论】:

  • 可以设置0dp高度。
  • 试过但没用。
  • 你添加了 gradle 吗?
  • @HardikParmar 是的,我已经添加了

标签: android xml android-layout android-constraintlayout


【解决方案1】:

请使用 app 而不是 android。

app:layout_constraintWidth_percent="0.5"    

另外,添加一个约束属性,如下所示:

    app:layout_constraintStart_toStartOf="parent"  

或

app:layout_constraintTop_toTopOf="parent"  

your_layout.xml

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

    <Button
        android:id="@+id/btn_temp"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintWidth_percent="0.5"
        android:text="Hello World!"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

【讨论】:

  • 错误已经消失,但视图仍然没有变化。
  • 请检查我的编辑答案。您必须设置约束布局的一个属性。
猜你喜欢
  • 1970-01-01
  • 2021-09-24
  • 2019-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-02
  • 2018-05-31
  • 2020-01-22
相关资源
最近更新 更多