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

相关推荐
通玄7 小时前
Jetpack Compose 入门系列(六):Navigation 3 页面导航
android
rocpp10 小时前
Android 多语言切换实战:从 Context 到 Android 13 应用语言适配
android·kotlin
释然小师弟11 小时前
Android开发十年:反思与回顾
android·后端·嵌入式
黄林晴13 小时前
用了这么久 Koin Scope,原来一直都用错了?
android·kotlin
爱勇宝1 天前
我做了一个只用来搜歌词的小 App
android·前端·后端
众少成多积小致巨1 天前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
Coffeeee1 天前
如何使用Glide和Coil加载WebP动图
android·kotlin·glide
Kapaseker2 天前
5 分钟搞懂 Kotlin DSL
android·kotlin
恋猫de小郭2 天前
AI Agent 开发究竟是啥?如何用 AI 开发 Agent ?深入浅出给你一套概念
android·前端·ai编程
黄林晴2 天前
Android 17 正式发布!target 37 一大批旧代码直接不能用了
android