關於android裏面Shape屬性的使用

                                                                                                      Shape屬性

Shape的中文意思是模型,形狀。android裏面的shape也是這個意思,它的存在就是爲了爲給用戶自定義圖形的提供解決方案。總而言之,你可以用它自定義做一些一些簡單的圖形。。。。。好像扯的有點多,,,嗯嗯,好吧,直接說用法吧:

在工程上右鍵新建android xml文件進入創建頁面,選擇Rescources Type爲Drawable

Root Eleum爲shape,File框填入你自定義的shape的名字。


好了,一個shape就創建好了。接下來進入shape的設計界面了:



以下是shape的一些屬性及其含義:

1)stroke 
   描述: stroke:邊框效果  相當於html中的盒子模型的border 
   屬性: android:width 描邊的寬度 
               android:color 描邊的顏色 
               android:dashWidth 表示邊框的樣式是虛線的寬度,
			             值爲0時,表示爲實線。
			             值大於0則爲虛線。 
                android:dashGap  表示描邊爲虛線時,
			             虛線之間的間隔 即"- - - " 
2)padding 
   描述:內部邊距,即內容與邊的距離 
   屬性: android:left  左內邊距 
               android:top   上內邊距 
               android:right  右內邊距 
               android:bottom 下內邊距 
3)corners 
  描述: corners: 圓角 
  屬性:  android:radius  半徑 
               android:topLeftRadius  左上角半徑 
               android:topRightRadius  右上角半徑 
               注意一下兩個屬性比較不同: 
               android:bottomLeftRadius 右下角半徑 
               android:bottomRightRadius 左下角半徑



4)solid  
    描述:內部填充 
    屬性  android:color 填充顏色 
5)gradient 
    描述: 漸變色 
    屬性: android:startColor  起始顏色 
                android:endColor    結束顏色 
                android:angle     漸變角度(PS:當angle=0時,漸變色是從左向右。然後逆時針方向轉,當angle=90時爲從下往上。angle必須爲45的整數倍) 
                android:type       漸變類型(取值:linear、radial、sweep) 
                   linear  線性漸變,這是默認設置 
                   radial  放射性漸變,以開始色爲中心。 
                   sweep   掃描線式的漸變。 
                android:centerColor  漸變中間顏色,即開始顏色與結束顏色之間的顏色 
                android:useLevel 如果要使用LevelListDrawable對象,就要設置爲true。設置爲true無漸變。false有漸變色 
                android:gradientRadius  漸變色半徑.當 android:type="radial" 時才使用。單獨使用 android:type="radial"會報錯。 
                android:centerX   漸變中心X點座標的相對位置 
                android:centerY   漸變中心Y點座標的相對位置
6)size  
    描述:size: 大小 
    屬性: android:width   表示形狀的寬度 
                android:height 表示形狀的高度

使用時直接用@drawable/myshape 便可。

效果:


實際開發中常常會結合selector將綁定不同shape實現動畫效果,如按鈕變色,背景動態改變等炫酷界面效果。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章