Taha wakeel
Taha wakeel

Reputation: 169

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.

Upvotes: 5

Views: 10516

Answers (1)

Viraj Patel
Viraj Patel

Reputation: 2393

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>

Upvotes: 18

Related Questions