Android初级进阶之Shape

简介: shape``` xml```rectangle圆角矩形图片xml```xml ```注使用bottomLeftRadius等属性,可以做出不同的效果,如左两边圆角,右两边不圆角等。

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

圆角矩形

图片

img_464be4590d7d16d19589f2d620eb52c4.png

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等属性,可以做出不同的效果,如左两边圆角,右两边不圆角等。

img_3a946bb4ff3831b718a68fa940e333dd.png

img_3470f739dfcb3c3b38d328f685bd88b0.png

圆角矩形-边框

图片

img_74b7e6794ad68f10d247e53cf94a304b.png
``` 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" />

img_7975693406cc06ddee00b763ac6b80ea.png

oval

实心圆

图片

img_d1e04daf0b2689985f88feeb31b4fd99.png

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>
```

实心圆-边框

图片

img_113b977f0bf82913c1e760ae786e85ce.png

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

图片

img_aace5bc3d00c90047f7b0f5067131558.png

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>
目录
相关文章
|
5月前
|
API Android开发
Android高手进阶教程(十五)之---通过Location获取Address的使用!
Android高手进阶教程(十五)之---通过Location获取Address的使用!
58 1
|
4月前
|
存储 算法 Java
Android 进阶——代码插桩必知必会&ASM7字节码操作
Android 进阶——代码插桩必知必会&ASM7字节码操作
210 0
|
5月前
|
缓存 网络协议 Java
挑战全网,史上最全Android开发进阶,跳槽复习指南(1),掌握这6大技能体系
挑战全网,史上最全Android开发进阶,跳槽复习指南(1),掌握这6大技能体系
|
5月前
|
算法 安全 Java
2024年Android最新知识体系最强总结(全方面覆盖Android知识结构,BAT面试&学习进阶)
2024年Android最新知识体系最强总结(全方面覆盖Android知识结构,BAT面试&学习进阶)
|
5月前
|
消息中间件 缓存 架构师
2024年阿里Android高级面试题分享,附学习笔记+面试整理+进阶书籍
2024年阿里Android高级面试题分享,附学习笔记+面试整理+进阶书籍
|
XML Android开发 数据格式
Android中利用shape属性自定义设置Button按钮
Android中利用shape属性自定义设置Button按钮
224 0
|
存储 JavaScript 数据可视化
Android自动生成Shape资源文件,迈出可视化脚手架第一步(上)
这章我们就进入到了撸码时刻,逐步来开发出一个一个应对我们Android场景的功能,这章对应的功能是,Shape的自动生成
133 0
|
5月前
|
Android开发
[Android]Shape Drawable
[Android]Shape Drawable
80 0
|
编解码 网络协议 Android开发
Android平台RTMP|RTSP直播播放器功能进阶探讨
很多开发者在跟我聊天的时候,经常问我,为什么一个RTMP或RTSP播放器,你们需要设计那么多的接口,真的有必要吗?带着这样的疑惑,我们今天聊聊Android平台RTMP、RTSP播放器常规功能,如软硬解码设置、实时音量调节、实时快照、实时录像、视频view翻转和旋转、画面填充模式设定、解码后YUV、RGB数据回调等:
184 0
|
数据可视化 Android开发
Android自动生成Shape资源文件(下)
这个Shape,在正常的开发中,无非就是,实心的,空心的,渐变的,左上右下带角度的,那么针对常见的几种方式,我们做好模板,然后根据你在可视化工具的选择,动态的进行改变即可。
109 0
Android自动生成Shape资源文件(下)