shape的簡單用法

shap節點-----------------------------------
定義shape的值,必須是下面的之一:
"rectangle" 矩陣,這也是默認的shape
"oval"    橢圓
"line"     一條水平的直線。這種shape必須使用 <stroke> 元素來定義這條線的寬度
"ring"    圓環
android:useLevel
Boolean類型。若是用在 LevelListDrawable裏,那麼就是true。若是一般不出現則爲false。
下面的屬性只有當 android:shape="ring"才使用:
android:innerRadius
尺寸。 內環的半徑。一個尺寸值(dip等等)或者一個尺寸資源。
android:thickness
尺寸。環的厚度,是一個尺寸值或尺寸的資源android


corners節點--------------------------------------------
<corners>
爲Shape建立一個圓角,只有shape是rectangle時候才使用。
android:radius
Dimension。圓角的半徑。會被下面每一個特定的圓角屬性重寫。
android:topLeftRadius
Dimension。top-left 設置左上角的半徑
android:topRightRadius
Dimension。top-right 設置右上角的半徑
android:bottomLeftRadius
Dimension。 設置右下角的半徑
android:bottomRightRadius
Dimension。設置左下角的半徑3d


gradient節點--------------------------------
<gradient>
指定這個shape的漸變顏色。
android:angle
Integer。漸變的角度。 0 表明從 left 到 right。90 表明bottom到 top。必須是45的倍數,默認爲0
android:centerX
Float。漸變中心的相對X座標,在0到1.0之間。
android:centerY
Float。漸變中心的相對Y座標,在0到1.0之間。
android:centerColor
Color。可選的顏色值。基於startColor和endColor之間。
android:endColor
Color。 結束的顏色。
android:gradientRadius
Float 。漸變的半徑。只有在 android:type="radial"才使用
android:startColor
Color。開始的顏色值。
android:type
Keyword。漸變的模式,下面值之一:
"linear" 線形漸變。這也是默認的模式
"radial" 輻射漸變。startColor即輻射中心的顏色
"sweep" 掃描線漸變。
android:useLevel
Boolean。若是在LevelListDrawable中使用,則爲truexml

 

padding節點-------------------------------------
<padding>
內容與視圖邊界的距離
android:left
Dimension。左邊填充距離.
android:top
Dimension。頂部填充距離.
android:right
Dimension。右邊填充距離.
android:bottom
Dimension。底部填充距離.ip


size節點-------------------------------------------
<size>
這個shape的大小。
android:height
Dimension。這個shape的高度。
android:width
Dimension。這個shape的寬度。
注意:默認狀況下,這個shape會縮放到與他所在容器大小成正比。當你在一個ImageView中使用這個shape,
你能夠使用 android:scaleType="center"來限制這種縮放。utf-8


solid節點----------------------------------------------
<solid>
填充這個shape的純色
android:color
Color。顏色值,十六進制數,或者一個Color資源資源


stroke節點-------------------------------------io

<stroke>
這個shape使用的筆畫,當android:shape="line"的時候,必須設置改元素。
android:width
   Dimension。筆畫的粗細。
android:color
Color。筆畫的顏色
android:dashGap
Dimension。每畫一條線就間隔多少。只有當android:dashWidth也設置了纔有效。
android:dashWidth
Dimension。每畫一條線的長度。只有當 android:dashGap也設置了纔有效。
android:dashGap和android:dashWidth設置這條線爲虛線的,其中android:dashWidth表示'-'這樣一個橫線的寬度,android:dashGap表示之間隔開的距離,容器


代碼---------------------------------
<!--圓環-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
//半徑
android:innerRadius="20dp"
//環的寬度
android:thickness="1dp"
android:useLevel="false">
//圓環的填充色
<solid android:color="#412684"/>
//邊界色
<stroke android:color="#624509"
android:width="3dp"/>coding

</shape>List


<!--線-->
<?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>

相關文章
相關標籤/搜索