我通过xml文件处理渐变。
问题是,尽管渐变效果很好,但我想要从一种颜色到另一种颜色的渐变过渡,而不是渐变。
似乎没有阶跃渐变的选项。我该怎么办?
发布于 2011-03-24 20:53:28
如果您可以/想要转移到编程解决方案,API允许您使用颜色步长创建渐变,并使用两个数组定义每种颜色的相对(0.0-1.0)位置:
// 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));
发布于 2012-09-12 23:50:02
您可以做的是创建一个背景布局,其中包含所需步骤的任意多个视图。然后为每个视图设置不同的渐变。
<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>
https://stackoverflow.com/questions/5418487
复制相似问题