【发布时间】:2017-04-09 05:02:12
【问题描述】:
我有另一个活动,它的布局有RelativeLayout、TextViews 和一个ImageView...这里没有问题。
通过下面的其他 Activity,我有许多 TextView 和一个 RelativeLayout。添加 Imageview 时,我收到以下错误:
错误:(190) 没有为属性 'srcCompat' 找到资源标识符 包 'com.example.ftonyan.userposts' 错误:(190)没有资源 在包中找到属性“srcCompat”的标识符 'com.example.ftonyan.userposts' 错误:任务执行失败 ':app:processDebugResources'。
com.android.ide.common.process.ProcessException: 无法执行 aapt
在添加 imageview 之前,这个有问题的活动的 layout.xml 的顶部如下所示(代码在模拟器上编译和运行)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
imageview 添加到调色板后,以下 2 行是红色的(注意第 2 行是系统添加的)。代码不再编译。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
下面是我的 Activity layout.xml。此布局中大约有 19 个 textView。为简洁起见,我没有包括所有这些。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/lblAddressees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/lblNick"
android:layout_toStartOf="@+id/nickName"
android:text="Addressees:" />
<Button
android:id="@+id/goBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="@android:color/transparent"
android:text="back" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button6"
android:layout_centerHorizontal="true"
android:layout_marginBottom="87dp"
android:srcCompat="@mipmap/ic_launcher" />
</RelativeLayout>
我在这里阅读了一些建议更改 apk/res-auto 行的帖子。但是,在系统添加之前,该行首先不在文件中。所以,不知道我应该怎么做才能解决这个问题。提前致谢
【问题讨论】:
-
你的问题不包括
srcCompat,那么这个错误是从哪里来的呢? -
你需要
srcCompat吗?android:src有什么问题? -
谢谢。我是新手。我不知道你的问题的答案。我在哪里寻找 srcCompat?我在项目的两个布局文件中进行了搜索。 srcCompat 也没有……或者那是 Java?
-
你说过“当你添加 ImageView”...请显示错误的代码
-
我正在查看设计模式下有问题的布局。我抓住 imageView 小部件并将其放在布局上。然后,当我构建和/或运行项目时,会出现上述错误。然后,当我从布局中删除 imageView 时,项目构建并再次运行,没有错误。
标签: java android android-layout android-imageview