android - 无法在 Android 中解析 ImageButton 的 id

标签 android android-imagebutton

我有一个带有 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,如图所示。 t

我会很感激每一条评论。

最佳答案

看起来很像 Android Studio 问题。您是否尝试过以下任何一种:

  • 用 gradle 文件重新同步项目
  • 清理和重建
  • 使cahce无效并重新启动?
  • 关于android - 无法在 Android 中解析 ImageButton 的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61478922/

    相关文章:

    android - 集成 Pusher Android Titanium 模块时出现运行时错误

    java - Gradle 同步失败版本不支持 ModelBuilder API,而版本为 3.3

    android - 想在我的应用程序 android 中包含动画

    android - 在 CardView 展开时滚动

    Android onClickListener 在复合 View 中不起作用

    android - 在 Android 中使用 XML 形状设置绘制矩形

    android - 在android中为 View (Imagebutton)的X和Y坐标获取0值

    Android ImageButton ListView

    android - 有没有办法在Android RelativeLayout中填充 parent 减去固定数字?

    java - 在 Android 中使用图库图像更改图像按钮