Android Shape 的使用
生活随笔
收集整理的这篇文章主要介绍了
Android Shape 的使用
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
学而时习,温故而知新。
今天复习shape 画各种常见类型的背景图
使用:
当在 java 代码R.drawable.文件的名称
当在布局中时 android:background=“@drawable/文件的名字”
位置在
res下面的drawable 里面
1 先看下shape可以指定几种类型
line 线行
oval 椭圆
rectangle 长方形
ring 环行
2 shape 里面常用的属性
2.1 corners 圆角
角度可以单独四个角 指定如下图
2.2 solid 填充属性 ,一般我们设置颜色,线的宽度 里面的属性一般就是color
2.3 stock 边的属性
里面的属性如下
2.4 size 大小设置 一般是设置画的背景大小
2.5 gradient 渐变属性,一般画颜色不同的背景 属性如下
2.6 padding 这个就是边距属性
显示画一些背景
1 带有圆角的长方形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><corners android:radius="10dp" /><solid android:color="@color/colorAccent" /><sizeandroid:width="200dp"android:height="44dp" /></shape>
效果图
2 画一个带边线的长方形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><corners android:radius="10dp" /><stroke android:color="@color/colorAccent" android:width="1dp" ><sizeandroid:width="200dp"android:height="44dp" /></shape>
效果图
3 上面2个圆角的长方形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><cornersandroid:topLeftRadius="20dp"android:topRightRadius="20dp" /><solid android:color="@color/colorAccent" /></shape>
效果图
4 画一个渐变色的背景图
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><gradientandroid:centerColor="#4A63FF"android:endColor="#6320DE"android:startColor="#558EFB" /><sizeandroid:width="200dp"android:height="100dp" />
</shape>
效果图
5 画一个圆
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><solid android:color="@color/colorAccent" /><sizeandroid:width="200dp"android:height="200dp" />
</shape>
效果图
6 画一个圆环
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><strokeandroid:width="10dp"android:color="@color/colorAccent" /><sizeandroid:width="200dp"android:height="200dp" />
</shape>
效果图
7 画一个有虚线组成的圆
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><strokeandroid:width="10dp"android:color="@color/colorAccent"android:dashGap="5dp"android:dashWidth="5dp"/><sizeandroid:width="200dp"android:height="200dp" />
</shape>
效果图
修改属性
8 变成虚线的长方形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><strokeandroid:width="10dp"android:color="@color/colorAccent"android:dashGap="5dp"android:dashWidth="50dp"/><sizeandroid:width="400dp"android:height="200dp" />
</shape>
效果图
9 改成椭圆
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><strokeandroid:width="10dp"android:color="@color/colorAccent"android:dashGap="5dp"android:dashWidth="50dp"/><sizeandroid:width="400dp"android:height="200dp" />
</shape>
效果图
10 画一个半圆
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><cornersandroid:topLeftRadius="180dp"android:topRightRadius="180dp" /><solid android:color="@color/colorAccent" /><sizeandroid:width="400dp"android:height="200dp" />
</shape>
效果图
总结
以上是生活随笔为你收集整理的Android Shape 的使用的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 考托福多少钱啊?
- 下一篇: Android layer-list 使