找不到显示属性'android:layout_constraintWidth_percent'的Android约束布局

Tah*_*eel 0 xml android android-layout android-constraintlayout

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

Vir*_*tel 6

请使用app代替android

app:layout_constraintWidth_percent="0.5"    
Run Code Online (Sandbox Code Playgroud)

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

    app:layout_constraintStart_toStartOf="parent"  
Run Code Online (Sandbox Code Playgroud)

要么

app:layout_constraintTop_toTopOf="parent"  
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)