androidparse-error

Why is Android Studio ScrollView, having a resource compilation fail


I am fairly new with Android Studio and have ran into a problem that I have not come across before. Within an xml layout I am having a ParseError on line 22, which is the layout_height for the ScrollView. The error says Resource Compilation Failed. I have checked any posts that are even remotely close to this issue and have had no luck so far. Any tips would be appreciated.

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

    <data>

        <variable
            name="orderModel"
            type="com.example.pizzaorder.model.OrderModel" />

        <variable
            name="sizeFragment"
            type="com.example.pizzaorder.SizeFragment" />
    </data>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/welcome"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="120dp"
                android:gravity="center"
                android:text="@string/welcome"
                android:textSize="24sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@+id/twelve_inch"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="32dp"
                android:layout_marginTop="72dp"
                android:layout_marginEnd="32dp"
                android:onClick="@{() -> sizeFragment.moveToBase(12)}"
                android:text="@string/size_twelve"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/welcome" />

            <Button
                android:id="@+id/eighteen_inch"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="32dp"
                android:onClick="@{() -> sizeFragment.moveToBase(18)}"
                android:text="@string/size_eighteen"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/twelve_inch" />

            <Button
                android:id="@+id/twenty_four_inch"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="32dp"
                android:onClick="@{() -> sizeFragment.moveToBase(24)}"
                android:text="@string/size_twenty_four"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/eighteen_inch" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

</layout>

Solution

  • As per the comment, remove height, width, and context from the layout tag and put it in the ScrollView tag. The layout tag does not support these attributes, it is only used to create the data binding and to hold the variables.