android - ANDROID - “ID“示例”已定义但未分配给任何视图”
问题描述
我在 ids.xml 中定义了 ID -><item name="example" type="id"/>
我在styles.xml中使用了这个ID,就像这样->
<style name="exampleStyle">
<item name="android:id">@id/example</item>
###rest of items (width, height etc.)
</style>
我在我的 ConstraintLayout 中使用了这种风格 ->
<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 工作室)显示错误“id 示例已定义但未分配给任何视图。
为什么它没有看到我只是通过样式使用了这个 id?我可以在不使用的情况下解决这个问题tools:ignore="UnknownId
吗?
解决方案
android:id
而不是在样式中使用“ ”,而是在ImageView
例如,在一个布局中,它可能有几个ImageView
. 所以你可以多次使用相同的样式。但是如果动作是基于 id 的,那么你就不能正确地使用它。
推荐阅读
- reactjs - Chart in d3js not showing up in react app
- tomcat - OKTA Single Sign on for a java application
- node.js - 如何使用 updateMany 从 Mongoose 的数组中删除对象?
- sql-server - 声明循环 SQL 以计算日期之间的值
- python - Matplotlib:使用 Python 3.9 在云函数中自定义字体
- python-3.x - 运行时出现 Kivy 错误:TypeError: run() 缺少 1 个必需的位置参数:'self'
- java - 将密码添加到没有任何密码的 Java 密钥工具的密钥库
- javascript - 待办事项列表中完成的元素数量
- python - 基于一列“分组”行,然后为现有其他列值的可能组合创建新列
- javascript - 如何直接控制 JavaScript MediaElement 库每页只显示一个音量控件?