【问题标题】:Adding PNG and color to background将PNG和颜色添加到背景
【发布时间】:2011-06-09 04:20:17
【问题描述】:

我有 LinearLayout,我有 png 用作瓷砖 - 但我也希望它后面的颜色是白色的。

这可能吗?

我的代码是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/LinearMain" android:background="@drawable/bcktiles">

而drawable是:

    <?xml version="1.0" encoding="utf-8"?>
 <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/bgsite" android:tileMode="repeat">
    </bitmap>

我不知道该放在哪里#fff

谢谢

【问题讨论】:

    标签: android


    【解决方案1】:

    您还可以通过以下方式创建复合可绘制对象:

    drawable/composite.xml:

    <layer-list 
        xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="color drawable" />
        <item android:drawable="drawable 1..." />
    </layer-list>
    

    对于你的颜色,你可以创建一个可绘制的形状:

    <shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
      <solid android:color="color" />
    </shape>
    

    【讨论】:

    【解决方案2】:

    在您的 LinearLayout 中,如果您要引用颜色资源,则需要使用 android:background="@color/myColor"。如果您不想将其存储为资源,也可以只输入android:background="#FFFFFFFF"

    【讨论】:

    • 但是我替换了可绘制的参考!
    • 您实际上只有一个位置可以在 LinearLayout 中放置背景,因此您必须在颜色或平铺之间进行选择。为什么不使用RelativeLayout,将背景设置为您的颜色,然后在其中放置一个设置为FILL_PARENT 的ImageView 来显示您的图块?这样,您仍然可以将其他视图置于图块之上。
    猜你喜欢
    • 2015-04-21
    • 1970-01-01
    • 2016-02-15
    • 2019-01-05
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    相关资源
    最近更新 更多