0
在Android Studio上,我所做的只是創建一個空白的Android項目,並將一個jpg圖像添加到res/drawable,名爲mllogo.jpg。然後,我將一個ImageView拖到活動的設計器視圖中,並從drawable中選擇圖像。當我嘗試運行它,我得到這個:Android Studio:找不到屬性'srcCompat'的資源標識符
No resource identifier found for attribute 'srcCompat' in package 'com.mysite.mysiteandroid'
我不知道我可以做錯了什麼。我只是將一個ImageView拖到佈局上。這裏發生了什麼事?
這是活動的xml:
<?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到這樣做的工作:
<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生成的。
請打開你的活動的XML文件,並張貼代碼 –
@RosárioPereiraFernandes我張貼。任何反饋?我所做的只是將ImageView拖到佈局上。 – Donato