Android使用shape定义带渐变色的背景

在drawable目录下创建文件bg_gradient.xml

文件内的内容如下:

<?xml version="1.0" encoding="utf-8"?>

<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">

<gradient android:type="linear" android:useLevel="true" android:startColor="#ff028f43" android:endColor="#ff6abf23" android:angle="90" />

<corners android:topLeftRadius="0dp" android:topRightRadius="0dp" android:bottomLeftRadius="36dp" android:bottomRightRadius="36dp" />

</shape>

angle表示渐变角度

渐变角度,仅用于线性渐变。必须是0-315范围内45的倍数。

angle: 0 从左到右

angle 90 从下往上

angle 180 从右往左

angle 270 从上往下

type : linear 直线

相关推荐
机智的张尼玛1 天前
我基于 Kotlin Multiplatform 实现了一套跨平台的弱网离线同步引擎
android·开源·kotlin
安卓修改大师1 天前
安卓修改大师反编译引擎Apktool深度解析:版本选择、参数说明与实战技巧
android
error:(1 天前
【系统与实战双精通】VS Code 调试 ROS2 Python 节点与 Launch 系统指南
android·java·python
黄林晴1 天前
Kuikly 是什么?和KMP有什么关系?
android·前端
帅次2 天前
Android 高级工程师面试:Kotlin 语法基础 近1年高频追问 22 题
android·面试·kotlin·扩展函数·空安全
想你依然心痛2 天前
嵌入式日志系统:分级日志、环形缓冲区与远程输出——运行时调试、非侵入
android·前端·javascript
用户69371750013842 天前
AI Agent 里的 Loop 到底是什么?
android·前端·后端
海天鹰2 天前
安卓分割空字符串数组长度为1
android
Coffeeee2 天前
从 Android 15 到 Android 17,谷歌猝不及防的音频改动
android·前端·google
用户69371750013842 天前
AI 领域的 Harness,到底是什么意思?
android·前端·后端