首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android Studio:在包中找不到属性'srcCompat‘的资源标识符

Android Studio:在包中找不到属性'srcCompat‘的资源标识符
EN

Stack Overflow用户
提问于 2017-02-18 06:29:26
回答 1查看 590关注 0票数 0

在Android Studio上,我所做的就是创建一个空白的Android项目,并在res/drawable中添加一个名为mllogo.jpg的jpg图像。然后,我将一个ImageView拖到该活动的designer视图上,并从可绘制中选择图像。当我尝试运行它时,我得到的结果是:

代码语言:javascript
运行
复制
No resource identifier found for attribute 'srcCompat' in package 'com.mysite.mysiteandroid'

我不确定我会做错什么。我刚把一个ImageView拖到布局上。这是怎么回事?

这是活动xml:

代码语言:javascript
运行
复制
<?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" xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context="io.testapp.myapplication.MainActivity">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!" android:id="@+id/textView"/>
    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" app:srcCompat="@drawable/mllogo"
            android:layout_marginLeft="29dp" android:layout_marginStart="29dp" android:layout_marginTop="73dp"
            android:id="@+id/imageView" android:layout_below="@+id/textView" android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"/>
</RelativeLayout>

将ImageView更改为以下内容会起作用:

代码语言:javascript
运行
复制
<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_below="@+id/textView"
        android:layout_toRightOf="@+id/textView" android:layout_toEndOf="@+id/textView"
        android:layout_marginLeft="63dp" android:layout_marginStart="63dp" android:layout_marginTop="166dp"
        android:id="@+id/imageView2"
        android:background="@drawable/mllogo"
/>

换句话说,删除app:srcCompat属性消除了错误。但是为什么呢?我没有添加这个属性。它是在我添加ImageView时由Android Studio生成的。

EN

回答 1

Stack Overflow用户

发布于 2017-02-18 19:43:38

您应该将Android Support library添加到您的项目中。为此,将编译行添加到build.gradle文件(应用程序级别):

代码语言:javascript
运行
复制
dependencies {
    compile 'com.android.support:appcompat-v7:25.1.1' //Your library version might not match, so change the number appropriately
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42308467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档