我有一个带有4个ImageButton的滚动视图。但是,当我在约束布局中定义约束时,我在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,如图所示。
我会很感激每条评论。
看起来很像是Android Studio问题。您是否尝试过以下任何一种方法:
好像您忘了在ID的开头添加+符号。
只需将出现错误的行替换为:
app:layout_constraintEnd_toStartOf="@+id/imageButton_2"