Android背景:使用颜色放置图像

时间:2012-02-06 15:20:59

标签: android android-layout

在Android Activity上,我想将图像设置为左下角的背景。以下是您的操作方法:Background Image Placement

但是,我还希望能够指定不是此图像的其余背景具有某种颜色。这可能吗?

(所以我的背景是一个纯色,一个角落有一个小徽标)

谢谢,

编辑: 我做了一个显然应该工作的测试项目,但它崩溃了。 https://github.com/jarofgreen/AndroidTestBackground E / AndroidRuntime(213):引起:android.view.InflateException:二进制XML文件行#2:错误导致类

4 个答案:

答案 0 :(得分:3)

是的:

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

    <ImageView
        android:layout_width="100dip"
        android:layout_height="100dip"
        android:layout_gravity="bottom|left"
        android:background="#FF0000"
        android:scaleType="fitXY" />

</LinearLayout>

答案 1 :(得分:1)

我通过使用9补丁图像解决了这个问题。

http://developer.android.com/guide/developing/tools/draw9patch.html

我使用大面积的背景颜色制作了9张图片,并将背景颜色设置为可展开区域。

9-patch

然后将此图像设置为视图的背景!

(有一件事我不明白,我认为内容只会放在可扩展区域,左边和底部留有很大的余量。我们会接受这是一个必要的牺牲,但实际上内容出现在背景的所有部分。)

答案 2 :(得分:1)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/your image"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/your Color">
    </LinearLayout>
</LinearLayout>

答案 3 :(得分:0)

使用具有两个图像的相对布局。第一个是您的徽标,它设置为在右下角对齐(宽度\高度缩放到它的实际大小)。第二个是您的背景图像,但是可以对齐,因为您将它的width \ height设置为fill_parent。