android 图形Shape Drawable

android图形 Shape Drawable

在res/drawable/目录下,创建图形资源文件 res/drawable/filename.xml,支持rectangle,oval,line,ring四种图形,其中默认是rectangle,也是用的最多的。图形资源大量用来设置为控件的背景。

在res/drawable/目录下新建一个rectangle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp"/>
    <solid android:color="@color/blue"/>
</shape>

生成一个矩形图形资源文件,填充蓝色,四个角圆角半径10dp
在这里插入图片描述

在res/drawable/目录下新建一个rectangle_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp"/>
    <gradient android:angle="0"
        android:startColor="@color/blue"
        android:endColor="@color/white"/>
    <stroke android:color="@color/white"
        android:width="5dp"
        android:dashWidth="10dp"
        android:dashGap="10dp"/>
</shape>

生成一个矩形图形资源文件,以渐变色填充,四个角圆角半径10dp,边界线高5dp,边界线宽10dp,边界线间隔10dp
在这里插入图片描述

在res/drawable/目录下新建一个oval.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <corners android:radius="10dp"/>
    <solid android:color="@color/blue"/>
</shape>

生成一个椭圆资源文件,以蓝色填充,椭圆半径10dp
在这里插入图片描述

在res/drawable/目录下新建一个line.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke
        android:width="10dp"
        android:color="@color/blue" />
</shape>

生成一条水平线,以蓝色填充,高度10dp,其中必须设置stroke属性
在这里插入图片描述

在res/drawable/目录下新建一个ring.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadius="20dp"
    android:thickness="30dp"
    android:useLevel="false">
    <solid android:color="@color/blue"/>
</shape>

生成一个圆环,内半径20dp,环的厚度30dp,填充蓝色

在这里插入图片描述

Shape为ring属性时,注意如下几点:
1、android:useLevel=”false”该属性须设置为false

android:useLevel="boolean" //如果当做是LevelListDrawable使用时值为true,否则为false

2、以下属性只适用于ring

android:innerRadius="dimension"     //内环半径  
android:innerRadiusRatio="float"    //内环半径相对于环的宽度的比例
android:thickness="dimension"   //环的厚度  
android:thicknessRatio="float"     //环的厚度相对于环的宽度的比例  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值