创建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检查它,但错误仍然存在,我不认为这是最好的解决方案。更可靠的解决方案?
答案 0 :(得分:0)
您收到重复的ID错误,因为android.support.v7.internal.widget.ActivityChooserView$InnerLayout
中有一个同名的视图。简单的答案是为ImageView
使用新名称,并在代码中的任何位置更新代码。
请问您为什么直接在布局中使用内部框架小部件?内部布局不应直接使用,并且可能随时更改,这可能会在将来破坏您的代码。更好的解决方案是创建自己的布局或使用具有类似功能的公共框架小部件。使用内部小部件需要您自担风险。