首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android背景:使用颜色放置图像

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

Stack Overflow用户
提问于 2012-02-06 23:20:59
回答 4查看 4.2K关注 0票数 1

在Android活动中,我想在左下角设置一个图像作为背景。下面是你怎么做的:Background Image Placement

但是,我也希望能够指定背景的其余部分不是此图像具有特定的颜色。这个是可能的吗?

(这样我就可以有一个纯色的背景,在一个角落里有一个小徽标)

谢谢,

编辑:我做了一个测试项目,看起来应该可以工作,但对我来说它崩溃了。https://github.com/jarofgreen/AndroidTestBackground E/AndroidRuntime(213):原因: android.view.InflateException:二进制XML文件第2行:膨胀类时出错

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-02-13 19:48:18

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

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

我制作了一个9补丁的图像,背景颜色的区域很宽,并将背景颜色设置为可扩展区域。

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

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

票数 1
EN

Stack Overflow用户

发布于 2012-02-06 23:24:35

是的,它是:

代码语言:javascript
复制
<?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>
票数 3
EN

Stack Overflow用户

发布于 2018-04-17 13:23:01

代码语言:javascript
复制
<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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9162367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档