在创建 apk 时出现以下错误:
“重复的 id @+id/image,已经在这个布局的前面定义了....布局中的 abc_activity_chooser_view.xml:58 (appcompat_v7)”
于是我清理了一下,还是一样。此文件中确实存在重复的 id @+id/image :
<?xml version="1.0" encoding="utf-8"?>
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="android.support.v7.internal.widget.ActivityChooserView$InnerLayout"
android:id="@+id/activity_chooser_view_content"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
style="?attr/activityChooserViewStyle">
<FrameLayout
android:id="@+id/expand_activities_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:focusable="true"
android:addStatesFromChildren="true"
android:background="?attr/actionBarItemBackground">
<ImageView android:id="@+id/image"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_gravity="center"
android:layout_marginTop="2dip"
android:layout_marginBottom="2dip"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
</FrameLayout>
<FrameLayout
android:id="@+id/default_activity_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:focusable="true"
android:addStatesFromChildren="true"
android:background="?attr/actionBarItemBackground">
<ImageView android:id="@+id/image"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_gravity="center"
android:layout_marginTop="2dip"
android:layout_marginBottom="2dip"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
</FrameLayout>
</view>
关于如何处理这个问题的任何想法?显然我不能只是重命名它。 我可以跳过在 Lint 中检查它,但错误仍然存在,我认为这不是最好的解决方案。还有更可靠的解决方案吗?
最佳答案
您收到重复 ID 错误,因为 android.support.v7.internal.widget.ActivityChooserView$InnerLayout
中有一个同名 View 。简单的答案是为您的 ImageView
使用一个新名称,并在您引用它的任何地方更新代码中的名称。
请问您为什么直接在布局中使用内部框架小部件?内部布局并不意味着可以直接使用,并且随时可能更改,这可能会在将来破坏您的代码。更好的解决方案是创建自己的布局或使用具有类似功能的公共(public)框架小部件。使用内部小部件的风险由您自行承担。
关于android - appcompat_v7 abc_activity_chooser_view.xml 中重复的 id @+id/image :58,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33226440/