android - 底部布局的渐变形状背景

标签 android background gradient shapes

这是一些我不明白的 UI 行为...

我想要的:

This is what I would like to achieve

我得到的:

This is real result

我的代码:

<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 View 模式下工作正常,但在其他版本上不工作)

最佳答案

我正在使用以下代码,它可以正常工作。

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

关于android - 底部布局的渐变形状背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5923447/

相关文章:

android - 如何在事务Firestore后读取对象?

html - 在 iPad/移动设备上缩小页面

android - 如何制作一个带倒圆角的矩形?

python - 噪声数据中的梯度,python

android - 在具有共享元素的 fragment 上输入转换以共享元素为目标

android - 使用 ACTION_VIEW 打开缓存目录中的文件

javascript - 如何使 HTML/CSS 幻灯片背景淡入淡出?

css - 如何创建此渐变?

opengl - OpenGL 上的三角形渐变

android - ArcGIS - 不满意的链接错误查找库返回 null - Hello World 示例应用程序