我需要创建一个高度为230dp的渐变(即不是整个屏幕),其余部分为纯色。我无法弄清楚如何做到这一点 - 我尝试的所有事情都以渐变扩展填充整个屏幕结束。我现在的XML看起来是这样的:不能缩放的渐变背景
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="230dp">
<shape android:shape="rectangle" >
<color android:color="#333333" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#333333"
android:startColor="#D9D9D9"
android:type="linear" />
<size android:height="230dp" />
</shape>
</item>
</layer-list>
我然后应用绘制为背景,以我的LinearLayout在XML:
<?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="#333333" >
<LinearLayout
android:id="@+id/container"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@drawable/grey_gradient_bg" >
<!-- a bunch of content, buttons, etc. -->
</LinearLayout>
</LinearLayout>
但梯度扩展以填充整个屏幕。
我尝试过使用PNG作为背景,但是我得到了the banding problems described here,并且修复程序还没有帮助我。
如果你的LinearLayout是另一个布局的孩子那么也许父母并不像你期待的那样伸展。你应该提供整个布局xlm让我们分析它。 – woodshy 2012-03-13 16:08:51
使用完整版式XML进行编辑。 – matt 2012-03-13 16:36:15