论坛
潜水/灌水快乐,沉淀知识,认识更多同行。
ToB圈子
加入IT圈,遇到更多同好之人。
朋友圈
看朋友圈动态,了解ToB世界。
ToB门户
了解全球最新的ToB事件
博客
Blog
排行榜
Ranklist
文库
业界最专业的IT文库,上传资料也可以赚钱
下载
分享
Share
导读
Guide
相册
Album
记录
Doing
搜索
本版
文章
帖子
ToB圈子
用户
免费入驻
产品入驻
解决方案入驻
公司入驻
案例入驻
登录
·
注册
只需一步,快速开始
账号登录
立即注册
找回密码
用户名
Email
自动登录
找回密码
密码
登录
立即注册
首页
找靠谱产品
找解决方案
找靠谱公司
找案例
找对的人
专家智库
悬赏任务
圈子
SAAS
IT评测·应用市场-qidao123.com
»
论坛
›
软件与程序人生
›
移动端开发
›
Android使用shape属性绘制边框内渐变色
Android使用shape属性绘制边框内渐变色
小秦哥
金牌会员
|
2024-8-8 20:51:24
|
显示全部楼层
|
阅读模式
楼主
主题
987
|
帖子
987
|
积分
2961
先上效果图
这是使用AndroidStudio绘制的带有渐变色的边框背景致
实现方法
项目中由于UI设计需求,必要给按钮、控件设置带有背景致效果的。以下是UI效果图。
这里我们使用shape属性来绘制背景效果。
shape属性介绍
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] > // 定义形状
<corners //圆角属性
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer" />
<gradient //渐变属性
android:angle="integer"
android:centerX="integer"
android:centerY="integer"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<padding //边距属性
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer" />
<size //大小属性
android:width="integer"
android:height="integer" />
<solid //填充属性
android:color="color" />
<stroke //描边属性
android:width="integer"
android:color="color"
android:dashWidth="integer"
android:dashGap="integer" />
</shape>
复制代码
Shape可以定义控件的一些展示效果,比方圆角,渐变,添补,描边,大小,边距;shape子标签就可以实现这些效果,shape子标签有下面几个属性:
corners,
gradient,
padding,
size,
solid,
stroke:
corners
(圆角)
代码
layer-list 是用来创建 图层列表的,通过它能创建出一些特殊的 drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--顶部的渐变色-->
<item
android:gravity="top">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="linear"
android:angle="90"
android:startColor="#0077b3c7"
android:endColor="#9077b3c7"
android:useLevel="false"/>
<size
android:width="100dp"
android:height="10dp" />
</shape>
</item>
<!--左侧的渐变色-->
<item
android:gravity="left">
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="linear"
android:angle="0"
android:startColor="#9077b3c7"
android:endColor="#0077b3c7"
android:useLevel="false"/>
<size
android:width="10dp"
android:height="100dp" />
</shape>
</item>
<!--右侧的渐变色-->
<item
android:gravity="right">
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="180"
android:startColor="#9077b3c7"
android:endColor="#0077b3c7"
android:useLevel="false"/>
<size
android:width="10dp"
android:height="100dp"/>
</shape>
</item>
<!--底部的渐变色-->
<item
android:gravity="bottom">
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="90"
android:centerX="0"
android:centerY="0"
android:startColor="#9077b3c7"
android:endColor="#0077b3c7"
android:useLevel="false"/>
<size
android:width="100dp"
android:height="10dp" />
</shape>
</item>
<!--边框线-->
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/button_text_color"/>
</shape>
</item>
</layer-list>
复制代码
绘制完毕后,直接到代码中引用即可
效果
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
本帖子中包含更多资源
您需要
登录
才可以下载或查看,没有账号?
立即注册
x
回复
使用道具
举报
0 个回复
倒序浏览
返回列表
快速回复
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
or
立即注册
本版积分规则
发表回复
回帖并转播
回帖后跳转到最后一页
发新帖
回复
小秦哥
金牌会员
这个人很懒什么都没写!
楼主热帖
Python教程(5)——Python的第一个程序 ...
Kubernetes(k8s)安装以及搭建k8s-Das ...
〖Python接口自动化测试实战篇⑤〗- 接 ...
网易云信实时视频直播在TCP数据传输层 ...
java递归简介说明
liunx速记
海量监控数据处理如何做,看华为云SRE ...
从 Stream 到 Kotlin 再到 SPL
【问题】为什么 System.Timers.Timer ...
那些年用过的机械键盘
标签云
AI
运维
CIO
存储
服务器
浏览过的版块
云原生
MES
DevOps与敏捷开发
程序人生
网络安全
Mysql
快速回复
返回顶部
返回列表