背景图像在Android Studio中不起作用。(尝试了StackOverflow上提供的所有以前的解决方案)

背景图像在Android Studio中不起作用。(尝试了StackOverflow上提供的所有以前的解决方案),android,android-layout,android-studio,Android,Android Layout,Android Studio,我正在制作一个咖啡订购应用程序,我想在其中放置一个完全覆盖整个屏幕的背景图像(注意:这些图像显示在我从谷歌上放置的可绘制文件夹中) 我尝试使用布局android:background=“@drawable/cof”放置背景图像,但它不起作用。它显示了以下错误: 我甚至试着把不同的图像放进去,但它不工作,并显示以下错误 布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns

我正在制作一个咖啡订购应用程序,我想在其中放置一个完全覆盖整个屏幕的背景图像(注意:这些图像显示在我从谷歌上放置的可绘制文件夹中)

我尝试使用布局
android:background=“@drawable/cof”
放置背景图像,但它不起作用。它显示了以下错误:

我甚至试着把不同的图像放进去,但它不工作,并显示以下错误

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_margin="16dp"
    android:background="@drawable/cof"

    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="QUANTITY"
        android:layout_marginBottom="16dp"
        />
     <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         >
        <Button
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:text="-"
            android:onClick="decrement"/>
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textSize="18sp"
             android:layout_marginLeft="8dp"
             android:layout_marginRight="8dp"
             android:text="2"
             />
         <Button
             android:layout_width="48dp"
             android:layout_height="48dp"
             android:text="+"
             android:onClick="increment"
             />

     </LinearLayout>

     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textSize="25sp"
         android:layout_marginTop="16dp"
         android:text="Price"
         android:layout_marginBottom="16dp"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="Rs 10"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:textSize="28sp"
        android:text="ORDER"
        android:onClick="submitOrder"/>
</LinearLayout>

可绘制文件不能是html文件

请参考可抽出式

如果只想放置图像,则接受.png、.jpg或.gif


如果要显示HTML页面,则必须使用。请检查名为“cof”的文件是否为可绘制资源。它应该是.png文件或.xml文件。如果是png文件,请尝试使用MS paint或Photoshop再次将其保存为png图像,有时,重命名或更改图像扩展名会导致Android Studio出现问题。

如果要显示html文件,则不能将.htm或.html文件设置为背景,必须使用WebView,通过重叠WebView上的其他视图,您可以将其视为背景。

可绘制的
文件夹只能有以下内容之一:资源类型:

位图文件(.png、.9.png、.jpg、.gif)或 编译成以下可绘制资源子类型::
Bitmap
文件-九个补丁(重新调整位图大小)-状态列表-形状-
动画绘图-其他绘图-


我也是android的初学者,但我认为这基本上发生在你没有使用正确格式的图像时。您应该使用.png格式。在我看来,加载背景图像的代码是正确的。

请提供错误文本和文件“cof”。很抱歉,忘记附加scrrenshot。好的,没问题,我将给出“预览屏幕”上出现的错误:渲染问题无法解决资源“@drawable/cof”。无法将@drawable/cof转换为可绘制文件“-这是预览屏幕上显示的消息。错在哪里。让我知道我能做些什么来完成我的工作我甚至尝试重新启动android studio(使catcher无效/重新启动),但它仍然不工作,并在预览屏幕上给我同样的消息。我现在该怎么办?帮助me@Ayush它有用吗?