【发布时间】:2021-01-30 10:24:03
【问题描述】:
我想在我的 Android 应用程序中显示一张图片。
如您所见,我将ImageView 放入我的布局中并使用android:src="@drawable/android" 引用它
图片路径是MyApp6/app/src/main/res/drawable/android/a.jpeg,我确定是正确的。
但是,在构建项目后,我收到了以下错误消息:
No resuorce found that matches the given name (at 'src' with value @drawable/android.")
我没有电脑,所以我使用助手。
这是我的 XML 布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff000"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tw2"
android:textSize="30dp"
android:layout_margin="16dp"
android:text="Güzel Sözler"
android:shadowColor="#00ccff"
android:shadowRadius="2"
android:shadowDx="1"
android:shadowDy="1"
android:textIsSelectable="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tw1"
android:textSize="15dp"
android:layout_margin="16dp"
android:text=""
android:shadowColor="#00ccff"
android:shadowRadius="2"
android:shadowDx="1"
android:shadowDy="1"
android:textIsSelectable="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn1"
android:text="random"
android:textSize="20dp"
android:background="#cae1ff"
android:textColor="#ff3030"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/android"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:gravity="center_horizontal|bottom"
android:text="Android Programlama"
android:textColor="#ffffff"
android:textSize="30sp"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>
【问题讨论】:
-
首先你需要确保你已经在你的drawable文件夹中添加了图片a.jpeg。如果您已正确添加,则无需使用
@drawable/android访问图像,而是使用@drawable/a,因为图像文件的名称是a.jpeg,而不是android.jpeg。 -
很遗憾,同样的错误还在继续
标签: java android xml android-studio android-layout