我有一个滚动视图,里面有4个ImageButtons。但是,当我在约束布局中定义约束时,XML文件会出现错误消息:"无法解析符号@id/imageButton"。我不理解这个错误消息,因为我已经定义了图像按钮的ID。有人能帮我吗?以下是代码的一部分:
<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>
错误消息例如在以下行中显示: “app:layout_constraintEnd_toStartOf =”@id/imageButton_2“”
这是Android Studio中xml文件中错误消息的屏幕截图。对我来说,引人注目的是我已经定义了imageButton_2的ID,正如您在图中所看到的那样。
![t](https://istack.dev59.com/hbWBt.webp)