Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在android中设置背景图像_Android_Background - Fatal编程技术网

无法在android中设置背景图像

无法在android中设置背景图像,android,background,Android,Background,我正在尝试更改我的背景图像。我认为我做错了什么,所以我寻找答案并找到了它 我的代码与答案完全一致,但是它不起作用。我可以很容易地改变背景的颜色,但是当我尝试放置背景图像时,它失败了。我的jpg(480X800)资源位于可绘制的hdpi中。我尝试将分辨率更改为800x480 到目前为止,我只编辑了activity_main.xml并添加了一些资源: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

我正在尝试更改我的背景图像。我认为我做错了什么,所以我寻找答案并找到了它

我的代码与答案完全一致,但是它不起作用。我可以很容易地改变背景的颜色,但是当我尝试放置背景图像时,它失败了。我的jpg(480X800)资源位于可绘制的hdpi中。我尝试将分辨率更改为800x480

到目前为止,我只编辑了activity_main.xml并添加了一些资源:

<FrameLayout 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:background="@drawable/vertical_lines"
    tools:context=".Main" >

    <!--
         The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc.
    -->

    <TextView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:text="@string/dummy_content"
        android:textColor="#33b5e5"
        android:textSize="50sp"
        android:textStyle="bold" />

    <!--
         This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows.
    -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true" 
        android:background="@drawable/vertical_lines" >

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="?buttonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay"
            android:orientation="horizontal"
            tools:ignore="UselessParent" >

            <Button
                android:id="@+id/dummy_button"
                style="?buttonBarButtonStyle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/dummy_button" />
        </LinearLayout>
    </FrameLayout>

</FrameLayout>


我想出来了。问题根本不在于我的代码。我使用过photoshop,出于某种原因,jpg文件保存在CMYK颜色模式下。在我将设置切换到RBG并将文件重新保存为png后,一切正常。我不敢相信我花了这么多时间在这个问题上,而问题甚至不在我的代码中。如果有人遇到类似的问题,希望这能节省他们的时间

您是否尝试过在根布局中设置android:fillViewport=“true”?另外,尝试只设置根布局而不设置任何子视图,并检查发生了什么。可能是某些内部视图导致了问题。谢谢,我尝试了fillViewport=“true”,但没有成功。我将尝试删除子项。确定当我删除xml中的子项并删除主项中的错误时(通过删除与它们对应的代码),当应用程序开始声明:打开跟踪文件时出错:没有这样的文件或目录(2)您尝试过清理项目吗?