首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何创建具有中间色阶的渐变?

如何创建具有中间色阶的渐变?
EN

Stack Overflow用户
提问于 2011-03-24 19:37:08
回答 2查看 1.2K关注 0票数 1

我通过xml文件处理渐变。

问题是,尽管渐变效果很好,但我想要从一种颜色到另一种颜色的渐变过渡,而不是渐变。

似乎没有阶跃渐变的选项。我该怎么办?

EN

回答 2

Stack Overflow用户

发布于 2011-03-24 20:53:28

如果您可以/想要转移到编程解决方案,API允许您使用颜色步长创建渐变,并使用两个数组定义每种颜色的相对(0.0-1.0)位置:

代码语言:javascript
运行
复制
// this creates a semi-lucid cylinder gradient
int[] colGreen =  {Color.parseColor("#006600"),
           Color.parseColor("#01cc00"),
           Color.parseColor("#119911"),
           Color.parseColor("#22bb33"),
           Color.parseColor("#ddffdd"),
           Color.parseColor("#006600") };

float[] pos = {0.0f, 0.25f, 0.5f, 0.55f, 0.85f, 1f};

LinearGradient gr = new LinearGradient(x0, y0, x1, y1, colGreen, pos, tilemode));
票数 2
EN

Stack Overflow用户

发布于 2012-09-12 23:50:02

您可以做的是创建一个背景布局,其中包含所需步骤的任意多个视图。然后为每个视图设置不同的渐变。

代码语言:javascript
运行
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/background"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <View
        android:id="@+id/gradient1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/gradient1" />

    <View
        android:id="@+id/gradient2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/gradient2" />

</LinearLayout>

<LinearLayout
    android:id="@+id/content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

</LinearLayout>

</RelativeLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5418487

复制
相关文章

相似问题

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