在Android活动中,我想在左下角设置一个图像作为背景。下面是你怎么做的:Background Image Placement
但是,我也希望能够指定背景的其余部分不是此图像具有特定的颜色。这个是可能的吗?
(这样我就可以有一个纯色的背景,在一个角落里有一个小徽标)
谢谢,
编辑:我做了一个测试项目,看起来应该可以工作,但对我来说它崩溃了。https://github.com/jarofgreen/AndroidTestBackground E/AndroidRuntime(213):原因: android.view.InflateException:二进制XML文件第2行:膨胀类时出错
发布于 2012-02-13 19:48:18
我通过使用9补丁图像解决了这个问题。
http://developer.android.com/guide/developing/tools/draw9patch.html
我制作了一个9补丁的图像,背景颜色的区域很宽,并将背景颜色设置为可扩展区域。

然后只需将此图像设置为视图的背景!
(我不理解的一件事是,我认为内容只会放在可扩展的区域,在左边和底部留出很大的空白。我们打算接受这是一种必要的牺牲,但实际上内容出现在背景的所有部分。)
发布于 2012-02-06 23:24:35
是的,它是:
<?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>发布于 2018-04-17 13:23:01
<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>https://stackoverflow.com/questions/9162367
复制相似问题