繁体   English   中英

Android背景:图像放置颜色

[英]Android Background: Image placement with a color

在Android活动上,我想将图像设置为左下角的背景。 操作方法如下: 背景图片放置

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

(因此,我可以使用一种纯色背景,在一个角上有一个小徽标)

谢谢,

编辑:我已经完成了一个显然应该工作的测试项目,但是它对我来说崩溃了。 https://github.com/jarofgreen/AndroidTestBackground E / AndroidRuntime(213):原因:android.view.InflateException:二进制XML文件第2行:膨胀类错误

是的:

<?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>
<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>

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

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

我制作了一个具有9个色块的图像,并具有较大的背景颜色区域,并将背景颜色设置为可扩展区域。

9补丁

然后只需将此图像设置为视图的背景即可!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM