Search code examples
androidandroid-imagebutton

Cannot resolve id of ImageButton in Android


I have a scroll view with 4 ImageButtons in it. However, when I define the constraints in the contraine layout I get the error message in the XML file: "Cannot resolve symbol @id/imageButton ". I do not understand this error message, as I have defined the id of the image buttons. Can anyone help me with that? Here is part of the code:

 <ScrollView
        app:layout_constraintTop_toBottomOf="@id/toolbar_mainActivity"
        app:layout_constraintBottom_toTopOf="@id/bottom_layout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_width="0dp"
        android:layout_height="0dp">
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:context=".MainActivity"
            tools:ignore="ExtraText">


            <ImageButton
                android:id="@+id/imageButton_1"
                android:layout_width="0dp"
                android:layout_height="128dp"
                android:layout_marginTop="12dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintEnd_toStartOf="@id/imageButton_2"
                app:layout_constraintHorizontal_chainStyle="spread"
                app:layout_constraintHorizontal_weight="1"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/test_dish_1" />

            <ImageButton
                android:id="@+id/imageButton_2"
                android:layout_width="0dp"
                android:layout_height="128dp"
                android:layout_marginTop="12dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_weight="1"
                app:layout_constraintStart_toEndOf="@id/imageButton_1"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/test_dish_1" />

            <ImageButton
                android:id="@+id/imageButton_4"
                android:layout_width="0dp"
                android:layout_height="128dp"
                android:layout_marginTop="12dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintEnd_toStartOf="@id/imageButton_3"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/imageButton_1"
                app:layout_constraintVertical_chainStyle="packed"
                app:srcCompat="@drawable/test_dish_1" />

            <ImageButton
                android:id="@+id/imageButton_3"
                android:layout_width="0dp"
                android:layout_height="128dp"
                android:layout_marginTop="12dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@id/imageButton_4"
                app:layout_constraintTop_toBottomOf="@id/imageButton_1"
                app:srcCompat="@drawable/test_dish_1" />






        </android.support.constraint.ConstraintLayout>
    </ScrollView>

The error is displayed for example in the following line: 'app:layout_constraintEnd_toStartOf="@id/imageButton_2"'

Here is a screenshot of the error message in the xml file in Android Studio. The striking thing for me is that I have defined the id for imageButton_2, as you can see in the figure.t

I'd appreciate every comment.


Solution

  • Looks pretty much like an Android Studio issue. Have you tried any of this:

    • re-sync the project with gradle files
    • clean and rebuild
    • invalidate cahce and restart?