shape:定义控件的几何形状,如定义一个圆角的Button,设置渐变色等;当使用shape时,在res/drawable下新建.xml文件选择shape;
二.shape中子元素的属性:
2.设置圆角:corners
5.设置一致颜色:solid
一.shape中的属性:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval":椭圆形状
shape="line":线型
shape="rectangle":矩形
shape="ring">二.shape中子元素的属性:
1.设置渐变色:gradient
<gradient
android:startColor="#030303":设置开始颜色
android:type="radial":设置渐变放式为放射式
type="linear":平行式渐变
type="sweep":扫描渐变
android:endColor="#fff000":设置终止颜色
android:gradientRadius="200%p":设置渐变半径,该属性只有当type="radial"时有效
android:centerColor="#2E8B57"/>:设置中间颜色2.设置圆角:corners
<corners android:radius="20dp":设置圆角的全部半径
android:topLeftRadius="40dp"设置左上角半径,类推。。。
android:topRightRadius="10dp"
android:bottomLeftRadius="50dp"
android:bottomRightRadius="20dp"/>3.设置内间距:padding
<padding android:top="20dp"
android:left="20dp"
android:right="20dp"
android:bottom="20dp"/>4.设置大小:size<size android:width="100dp"
android:height="100dp"/>5.设置一致颜色:solid
<solid android:color="#ff00ff"/>:设置该属性后,不会再有渐变效果6.进行描边:stroke
<stroke android:width="10dp":描笔的高度(不是宽度)
android:color="#ff00ff":描笔的颜色
android:dashWidth="20dp":描笔的宽度
android:dashGap="10dp"/>:相邻描笔之间的间隔
本文介绍如何在Android中使用XML的shape元素进行UI美化,特别是通过设置gradient属性来实现渐变色效果,提升应用视觉体验。
862

被折叠的 条评论
为什么被折叠?



