底部布局的渐变形状背景

3

这里有一些UI行为我不理解...

我的期望:

这是我想要实现的效果

实际得到的结果:

这是真实的结果

我的代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/black_to_white" />
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blue_to_red" />
</LinearLayout>

背景代码:(两个代码相同,除了颜色)

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#000000"
        android:endColor="#ffffff"
        android:angle="270" />
</shape>

我该如何让我的第二个渐变从屏幕中间开始呈蓝色?

(我注意到这种渐变在Android 3.0视图模式下运行良好,但在其他版本上不行)


如果您提供可绘制的xml而不是不起作用的内容,那就更好了。另外,您是否已经尝试为两个framelayout使用相同的黑白背景? - harism
2个回答

1

我正在使用以下代码,它可以按照您的要求正常工作。

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#151B8D"
        android:endColor="#ff0000"
        android:angle="270" />
</shape>

0
问题在于你的颜色代码中缺少 alpha 值:
#[alpha][red][green][blue]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接