Android初级进阶之Shape

shape

``` xml
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle|oval|ring|line"><!--形状-->

<solid /><!--背景颜色-->
<corners /><!--角度,圆角-->
<gradient /><!--线性变化-->
<size /><!--大小-->
<stroke/><!--边框-->
</shape>
```

rectangle

圆角矩形

图片

xml

```xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="8dp" />
    <padding
        android:bottom="7dp"
        android:left="7dp"
        android:right="7dp"
        android:top="7dp" />
    <solid android:color="#f60" />
</shape>
```


使用bottomLeftRadius等属性,可以做出不同的效果,如左两边圆角,右两边不圆角等。

圆角矩形-边框

图片

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


虚线:

<stroke
    android:width="10dp"
    android:dashGap="3dp"<!--虚线间隔-->
    android:dashWidth="13dp"<!--虚线宽度-->
    android:color="#f60" />

oval

实心圆

图片

xml

```xml 
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false"
>

<solid android:color="#f60" />
<size
    android:width="50dp"
    android:height="50dp" />

</shape>
```

实心圆-边框

图片

xml

```xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<solid android:color="#03a9f4" />
<size
    android:width="20dp"
    android:height="20dp" />
<stroke
    android:width="5dp"
    android:color="#f60" />
</shape>    
```

注:
虚线等与矩形相同

ring

图片

xml

```xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:useLevel="false"
android:innerRadiusRatio="4"
android:thicknessRatio="8">
<solid android:color="#f00" />

<size
    android:width="100dp"
    android:height="100dp" />
</shape>

# 微信公众号

![AndroidRookie](https://upload-images.jianshu.io/upload_images/1760510-4ba94d021dc969fe.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 因为在iOS中视图的切角是很容易的,包括边框的颜色,圆角的弧度等等很容易设置,但是在HS2.0中Android开发...
    小白猿阅读 1,352评论 1 2
  • 摘抄自以下博客 https://www.cnblogs.com/popfisher/p/6238119.html ...
    Maybe_G阅读 1,060评论 0 0
  • 原创文章,转载请注明:转载自Keegan小钢 并标明原文链接:http://keeganlee.me/post/a...
    于加泽阅读 1,665评论 0 5
  • ANDROID样式的开发:SHAPE篇 转载自Keegan小钢并标明原文链接:http://keeganlee.m...
    一点墨汁阅读 840评论 0 1
  • 概述 今天我们来探究一下android的样式。其实,几乎所有的控件都可以使用 background属性去引用自定义...
    CokeNello阅读 4,912评论 1 19