小编典典

如何在android中制作渐变背景

all

我想创建渐变背景,其中渐变位于上半部分,下半部分为纯色,如下图所示:

我不能,因为它会centerColor蔓延到底部和顶部。

在按钮的渐变中,一条白色的水平线在蓝色上向顶部和底部逐渐消失。

如何制作像第一张图片一样的背景?我怎样才能使centerColor不散开的小?

这是上面背景按钮的 XML 中的代码。

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <gradient 
        android:startColor="#6586F0"
        android:centerColor="#D6D6D6"
        android:endColor="#4B6CD6"
        android:angle="90"/>
    <corners 
        android:radius="0dp"/>


</shape>

阅读 68

收藏
2022-04-29

共1个答案

小编典典

您可以通过使用
xml图层列表
将顶部和底部“带”组合到一个文件中来创建这种“半渐变”外观。每个波段都是一个 xml 形状。

2022-04-29