Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Constraint Layout showing attribute 'android:layout_constraintWidth_percent' not found

I searched a lot for this error but ended up seeing that everyone is suggesting of uninstalling android studio and reinstalling it with all sdk work which is not feasible to me. How can we remove this error in a decent way, please refer me to the answer if anyone has already given the right one.

like image 806
Taha wakeel Avatar asked Dec 03 '22 19:12

Taha wakeel


1 Answers

Please use app instead of android.

app:layout_constraintWidth_percent="0.5"    

Also, Add one constraint property like below:

    app:layout_constraintStart_toStartOf="parent"  

or

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>
like image 191
Viraj Patel Avatar answered Dec 06 '22 11:12

Viraj Patel