我有一个带有 4 个 ImageButtons 的 ScrollView 。但是,当我在约束布局中定义约束时,我在 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 问题。您是否尝试过以下任何一种:
关于android - 无法在 Android 中解析 ImageButton 的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61478922/