shape的简单用法
shap節(jié)點(diǎn)-----------------------------------
定義shape的值,必須是下面的之一:
"rectangle" 矩陣,這也是默認(rèn)的shape
"oval" 橢圓
"line" 一條水平的直線。這種shape必須使用 <stroke> 元素來定義這條線的寬度
"ring" 圓環(huán)
android:useLevel
Boolean類型。如果用在 LevelListDrawable里,那么就是true。如果通常不出現(xiàn)則為false。
下面的屬性只有當(dāng) android:shape="ring"才使用:
android:innerRadius
尺寸。 內(nèi)環(huán)的半徑。一個(gè)尺寸值(dip等等)或者一個(gè)尺寸資源。
android:thickness
尺寸。環(huán)的厚度,是一個(gè)尺寸值或尺寸的資源
corners節(jié)點(diǎn)--------------------------------------------
<corners>
為Shape創(chuàng)建一個(gè)圓角,只有shape是rectangle時(shí)候才使用。
android:radius
Dimension。圓角的半徑。會(huì)被下面每個(gè)特定的圓角屬性重寫。
android:topLeftRadius
Dimension。top-left 設(shè)置左上角的半徑
android:topRightRadius
Dimension。top-right 設(shè)置右上角的半徑
android:bottomLeftRadius
Dimension。 設(shè)置右下角的半徑
android:bottomRightRadius
Dimension。設(shè)置左下角的半徑
gradient節(jié)點(diǎn)--------------------------------
<gradient>
指定這個(gè)shape的漸變顏色。
android:angle
Integer。漸變的角度。 0 代表從 left 到 right。90 代表bottom到 top。必須是45的倍數(shù),默認(rèn)為0
android:centerX
Float。漸變中心的相對(duì)X坐標(biāo),在0到1.0之間。
android:centerY
Float。漸變中心的相對(duì)Y坐標(biāo),在0到1.0之間。
android:centerColor
Color??蛇x的顏色值?;趕tartColor和endColor之間。
android:endColor
Color。 結(jié)束的顏色。
android:gradientRadius
Float 。漸變的半徑。只有在 android:type="radial"才使用
android:startColor
Color。開始的顏色值。
android:type
Keyword。漸變的模式,下面值之一:
"linear" 線形漸變。這也是默認(rèn)的模式
"radial" 輻射漸變。startColor即輻射中心的顏色
"sweep" 掃描線漸變。
android:useLevel
Boolean。如果在LevelListDrawable中使用,則為true
?
padding節(jié)點(diǎn)-------------------------------------
<padding>
內(nèi)容與視圖邊界的距離
android:left
Dimension。左邊填充距離.
android:top
Dimension。頂部填充距離.
android:right
Dimension。右邊填充距離.
android:bottom
Dimension。底部填充距離.
size節(jié)點(diǎn)-------------------------------------------
<size>
這個(gè)shape的大小。
android:height
Dimension。這個(gè)shape的高度。
android:width
Dimension。這個(gè)shape的寬度。
注意:默認(rèn)情況下,這個(gè)shape會(huì)縮放到與他所在容器大小成正比。當(dāng)你在一個(gè)ImageView中使用這個(gè)shape,
你可以使用 android:scaleType="center"來限制這種縮放。
solid節(jié)點(diǎn)----------------------------------------------
<solid>
填充這個(gè)shape的純色
android:color
Color。顏色值,十六進(jìn)制數(shù),或者一個(gè)Color資源
stroke節(jié)點(diǎn)-------------------------------------
<stroke>
這個(gè)shape使用的筆畫,當(dāng)android:shape="line"的時(shí)候,必須設(shè)置改元素。
android:width
Dimension。筆畫的粗細(xì)。
android:color
Color。筆畫的顏色
android:dashGap
Dimension。每畫一條線就間隔多少。只有當(dāng)android:dashWidth也設(shè)置了才有效。
android:dashWidth
Dimension。每畫一條線的長度。只有當(dāng) android:dashGap也設(shè)置了才有效。
android:dashGap和android:dashWidth設(shè)置這條線為虛線的,其中android:dashWidth表示'-'這樣一個(gè)橫線的寬度,android:dashGap表示之間隔開的距離,
代碼---------------------------------
<!--圓環(huán)-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
//半徑
android:innerRadius="20dp"
//環(huán)的寬度
android:thickness="1dp"
android:useLevel="false">
//圓環(huán)的填充色
<solid android:color="#412684"/>
//邊界色
<stroke android:color="#624509"
android:width="3dp"/>
</shape>
<!--線-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
//邊界色
<stroke android:color="@android:color/black"
//邊界色的高度
android:width="1dp"/>
</shape>
<!--圓角矩形and橢圓-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"|oval
android:useLevel="false"
>
//填充色
<solid android:color="@android:color/holo_blue_bright"/>
//角度
<corners android:radius="20dip"/>
//邊界
<stroke android:width="1dp"
/>
</shape>
<!--矩形-->
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:useLevel="false">
//填充色
<!--<solid android:color="@android:color/black"/>-->
//邊界
<stroke android:color="@android:color/black"
android:width="1dp"/>
</shape>
轉(zhuǎn)載于:https://www.cnblogs.com/xiguameng/p/5957624.html
總結(jié)
以上是生活随笔為你收集整理的shape的简单用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python画图如何调整图例位置_Pyt
- 下一篇: android app反解工具,安卓反编