【问题标题】:Android Layout background image and colourAndroid Layout 背景图片和颜色
【发布时间】:2026-01-13 05:15:01
【问题描述】:

我需要添加什么,以便我有一个背景图像和 main.xml 的背景颜色

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="330dp"
android:layout_height="600dp"
android:layout_gravity="center|center_vertical"
android:background="@drawable/background"
>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    您应该能够简单地填充父级,然后相应地设置您的背景图像。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    >
    

    【讨论】:

    • 问题是他需要背景图像和颜色,而不仅仅是填充整个布局的背景图像。
    • 回答我自己的问题,这甚至不是正确的答案,我问的问题。 2 年后 android:background="@color/white" 在 strings.xml 添加 #FFFFFF*.com/questions/2748830/…