https://developer.android.google.cn/guide/topics/resources/drawable-resource.html
为什么这么写名字呢?因为我想强调,xml 里面用 <shape> 标签定义出来的 drawable 并不是 ShapeDrawable,而是 GradientDrawable。
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] >
<corners
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer" />
<gradient
android:angle="integer"
android:centerX="float"
android:centerY="float"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<padding
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer" />
<size
android:width="integer"
android:height="integer" />
<solid
android:color="color" />
<stroke
android:width="integer"
android:color="color"
android:dashWidth="integer"
android:dashGap="integer" />
</shape>
上面的链接中,对各属性有比较详细的解释,所以我只打算写几个我以前不太注意的属性,然后贴几张图说明下 <shape> 大概都能做到什么效果。
size:默认情况下,形状按照此处定义的尺寸按比例缩放至容器视图的大小。在 ImageView 中使用形状时,可通过将 android:scaleType
设置为 "center"
来限制缩放。*如果是用过背景的话,基本上还是会变形填充 View。
solid:实色填充
stroke:边框
gradient:渐变色
下面是一些图,来源于其他帖子。

http://blog.csdn.net/linmiansheng/article/details/18902603
http://blog.csdn.net/linmiansheng/article/details/18912905





网友评论