安卓 - "The id "示例" is defined but not assigned to any views"



i在ids.xml-> <item name="example" type="id"/>

中定义ID

我在styles.xml中使用了此ID->

<style name="exampleStyle">
     <item name="android:id">@id/example</item>
     ###rest of items (width, height etc.)
</style>

,我在这样的约束中使用了这种样式 ->

    <Button
        android:id="@+id/testButton"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toStartOf="@+id/goNextButton"/>
    <ImageView
        style="@style/exampleStyle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

最终IDE(Android Studio)显示了错误:" ID示例是定义但未分配给任何视图的错误。

为什么看不到我只是通过样式使用了此ID?我可以不使用tools:ignore="UnknownId

解决此问题

,而不是在样式中使用" android:id",在 ImageView

中使用它

在一个布局的示例中,它可能具有多个ImageView。因此,您可以多次使用相同的样式。但是,如果操作基于ID,则无法正确使用此操作。

相关内容

最新更新