android shape不可用_Android shape的使用详解

写在最前:不管在什么系统中,如果你应用的图片资源比较多的话,会导致安装包较大,比如四角有弧度的长方形、圆形、正方形等等简单图形,完全没有比较实用图片,在Android中如何优雅的避免这个问题呢,就是使用shape了。

1.新建文件

首先在你的项目下新建drawable文件夹,你的shape xml文件就放到这个地下,然后新建Android xml文件,如图:

新建xml文件

2.下面来介绍一下shape的属性

属性

如图,shape有6个属性,分别为:

corners:设置圆角,即四个角的弧度

gradient:颜色渐变

padding:间隔,xml里经常用到,不比多解释

size:长宽

solid:填充物,只有一个属性 -> 颜色

stroke:设置图片边缘颜色

来看一下官方给我的详细解释:

xmlns:android="http://schemas.android.com/apk/res/android"

android:shape=["rectangle" | "oval" | "line" | "ring"] >

android:radius="integer"

android:topLeftRadius="integer"

android:topRightRadius="integer"

android:bottomLeftRadius="integer"

android:bottomRightRadius="integer" />

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"] />

android:left="integer"

android:top="integer"

android:right="integer"

android:bottom="integer" />

android:width="integer"

android:height="integer" />

android:color="color" />

android:width="integer"

android:color="color"

android:dashWidth="integer"

android:dashGap="integer" />

形状的属性,只有这6种,下面详细介绍一下6种属性下的各个属性的意义,

**1).corners:Creates rounded corners for the shape. Applies only when the shape is a rectangle.创建圆角的形状。仅适用于当其形状是一个长方形

android:radius="20dp" 为角的弧度,值越大角越圆。

android:topRightRadius="20dp" 右上角

android:bottomLeftRadius="20dp" 右下角

android:topLeftRadius="1dp" 左上角

android:bottomRightRadius="0dp" 左下角

一个提示:bottomLeftRadius 是右下角,而不是左下角,谨记谨记,其实记反了也没有多大影响。

2).gradient:Specifies a gradient color for the shape.指定一个渐变颜色的形状。

android:startColor 起始颜色

android:endColor 结束颜色

android:centerColor 中心颜色

android:angle 渐变角度,必须为45的整数倍。

android:type 渐变模式默认为linear,即线性渐变,可以指定渐变为径向渐变,android:type="radial"

android:gradientRadius="50" 径向渐变需要指定半径

android:useLevel 值为true或false,至今不知道有什么作用

3)padding : 定义内容离边界的距离

android:bottom="2dp"

android:left="2dp"

android:right="2dp"

android:top="2dp"

4)size:The size of the shape.形状的长宽

android:height="100dp"

android:width="100dp"

5)solid :A solid color to fill the shape.填充颜色

android:color 指定填充的颜色

6)stroke:A stroke line for the shape.图形边缘画线

android:width="2dp" 描边的宽度

android:color="#FFFFFF" 描边的颜色

android:dashWidth 虚线中这样一个'-'横线的宽度

android:dashGap 两个'-'之间的距离

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值