如何在android中制作渐变背景 [英] How to make gradient background in android

查看:23
本文介绍了如何在android中制作渐变背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create gradient background where the gradient is in the top half and there's a solid color in the bottom half, like in this image below:

我不能,因为 centerColor 展开以覆盖底部和顶部.

I can't because the centerColor spreads out to cover the bottom and top.

如何制作与第一张图片一样的背景?如何制作不散开的小centerColor?

How can I make a background like the first image? How can I make small centerColor that's not spread out?

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

This is code in XML of background button above.

<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>

推荐答案

您可以使用 xml 创建这种半渐变"外观 Layer-List 将顶部和底部的带"合并到一个文件中.每个波段都是一个 xml 形状.

You can create this 'half-gradient' look by using an xml Layer-List to combine the top and bottom 'bands' into one file. Each band is an xml shape.

有关详细教程,请参阅关于 SO 的先前答案:多渐变形状.

See this previous answer on SO for a detailed tutorial: Multi-gradient shapes.

这篇关于如何在android中制作渐变背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆