android中shape的使用
来源:互联网 发布:下载布鲁帝同志软件 编辑:程序博客网 时间:2024/06/05 07:02
1.官方文档中的shape基本语法示例:
<?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>
2.shape根节点
shape的属性:
android:shape 表示通过当前shape定义出一个什么形状, 取值有四种,分别是: rectangle 矩形, oval 椭圆,ring 环形 ,line 线
仅当 android:shape=”ring” 如下时才使用以下属性:
android:innerRadius 尺寸。环内部(中间的孔)的半径,以尺寸值或尺寸资源表示。android:innerRadiusRatio 浮点型。环内部的半径,以环宽度的比率表示。例如,如果 android:innerRadiusRatio="5",则内半径等于环宽度除以 5。此值被 android:innerRadius 覆盖。默认值为 9。android:thickness 尺寸。环的厚度,以尺寸值或尺寸资源表示。android:thicknessRatio 浮点型。环的厚度,表示为环宽度的比率。例如,如果 android:thicknessRatio="2",则厚度等于环宽度除以 2。此值被 android:innerRadius 覆盖。默认值为 3。android:useLevel 布尔值。如果这用作 LevelListDrawable,则此值为“true”。这通常应为“false”,否则形状不会显示。
3. shape的子节点
corners 圆角 (该属性只针对shape取值为rectangle时有效)gradient 渐变色(形状中的颜色渐变)solid 填充色/固定色stroke 边线(就是形状最边缘的描线)size 尺寸大小(一般不用定义)padding 内容距shape边界的距离(即边距。注意,因shape一般用做背景,所以这里的内容指的是以shape为背景的控件。用的比较少)
注意:
- solid 和gradient一般只使用一个,因为如果在代码中同时定义了solid和gradient,后定义的会覆盖先定义的一个。
3.1corners 圆角,只有当根节点的shape取值是rectangle时有效
属性:
android:radius 尺寸。所有角的半径,以尺寸值或尺寸资源表示。对于每个角,这会被以下属性覆盖。android:topLeftRadius 尺寸。左上角的半径,以尺寸值或尺寸资源表示。android:topRightRadius 尺寸。右上角的半径,以尺寸值或尺寸资源表示。android:bottomLeftRadius 尺寸。左下角的半径,以尺寸值或尺寸资源表示。android:bottomRightRadius 尺寸。右下角的半径,以尺寸值或尺寸资源表示。
注:(最初)必须为每个角提供大于 1 的角半径,否则无法产生圆角。如果希望特定角不要倒圆角,解决方法是使用 android:radius 设置大于 1 的默认角半径,然后使用实际所需的值替换每个角,为不希望倒圆角的角提供零(“0dp”)。
3.2 gradient 指定形状的渐变颜色
属性:
android:angle 整型。渐变的角度(度)。0 为从左到右,90 为从上到上。必须是 45 的倍数。默认值为 0。android:centerX 浮点型。渐变中心的相对 X 轴位置 (0 - 1.0)。android:centerY 浮点型。渐变中心的相对 Y 轴位置 (0 - 1.0)。android:centerColor 颜色。起始颜色与结束颜色之间的可选颜色,以十六进制值或颜色资源表示。android:endColor 颜色。结束颜色,表示为十六进制值或颜色资源。android:gradientRadius 浮点型。渐变的半径。仅在 android:type="radial" 时适用。android:startColor 颜色。起始颜色,表示为十六进制值或颜色资源。android:type 关键字。要应用的渐变图案的类型。有效值为: 值 说明 "linear" 线性渐变。这是默认值。 "radial" 径向渐变。起始颜色为中心颜色。 "sweep" 流线型渐变。android:useLevel 布尔值。如果这用作 LevelListDrawable,则此值为“true”。
3.3 padding 要应用到包含视图元素的内边距(这会填充视图内容的位置,而非形状)
属性:
android:left 尺寸。左内边距,表示为尺寸值或尺寸资源android:top 尺寸。上内边距,表示为尺寸值或尺寸资源android:right 尺寸。右内边距,表示为尺寸值或尺寸资源android:bottom 尺寸。下内边距,表示为尺寸值或尺寸资源
3.4 size 形状的大小
属性:
android:height 尺寸。形状的高度,表示为尺寸值或尺寸资源android:width 尺寸。形状的宽度,表示为尺寸值或尺寸资源
注:默认情况下,形状按照此处定义的尺寸按比例缩放至容器视图的大小。在 ImageView 中使用形状时,可通过将 android:scaleType 设置为 "center" 来限制缩放。
3.5 solid 用于填充形状的纯色
属性:
android:color 颜色。应用于形状的颜色,以十六进制值或颜色资源表示。
3.6 stroke 形状的笔划中线
属性:
android:width 尺寸。线宽,以尺寸值或尺寸资源表示。android:color 颜色。线的颜色,表示为十六进制值或颜色资源。android:dashGap 尺寸。短划线的间距,以尺寸值或尺寸资源表示。仅在设置了 android:dashWidth 时有效。android:dashWidth 尺寸。每个短划线的大小,以尺寸值或尺寸资源表示。仅在设置了 android:dashGap 时有效。
Android官方文档
阅读全文
1 0
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- Android中shape的使用
- ANDROID中SHAPE的使用
- Android中shape的使用
- 查词典(查一个词后面的东西)
- hihoCoder 1105 : 题外话·堆
- flume-NG整合hdfs和kafka
- 简单常用的一个reset.css
- QT QML初体验随笔之QQuickView(11)
- android中shape的使用
- 简述 Docker比你想象的简单
- 买电脑要看哪些参数?(个人拙见)
- c++数据结构的实现
- HRegionServer的详解
- 为什么JAVA文件中只能含有一个Public类
- RocketMQ之术语了解
- 030-Java-21
- sklearn与GBDT入门案例