Issue
I created a fragment_b.xml file in my resources/layout folder. On my two buttons I get the following warning:
Element Button is not allowed here
Why is this warning popping up? My code is working fine.
fragment_b.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<Button
android:id="@+id/btn_fragment_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/go_to_fragment_c"
app:layout_constraintBottom_toTopOf="@id/btn_nagivate_to_fragment_f"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<Button
android:id="@+id/btn_nagivate_to_fragment_f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/go_to_fragment_f"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_fragment_b"
android:layout_marginTop="@dimen/a_lot_of_margin"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Solution
This will happen if you don't have the androidx ConstraintLayout library added as a dependency in your gradle files.
In your app/build.gradle file, in the dependencies
block, add this:
dependencies {
// ...
implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta3"
}
Of course you can use a different library version, but the androidx.constraintlayout:constraintlayout:
part is important.
Once that's done, do a gradle sync and rebuild your project and the warning should go away.
Answered By - Ben P.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.