標籤:
android:shape這個檔案或者說屬性是控制組件特性特別有用,往上搜刮的內容講解很迂腐,還是自己上手試了一下才感覺稍微入了門,不多說,上代碼。
布局檔案送上:<!-- lang: java --><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity" ><Button android:id="@+id/btnTest" android:layout_width="100dp" android:layout_height="100dp" android:text="組件" android:layout_centerInParent="true" />
Button的原始特性![可以看出,照片很呆板][1][1]: http://static.oschina.net/uploads/space/2015/0301/141755_uycv_734421.jpg下面介紹shape裡第一個屬性:gradient ,這個屬性工作表示,組件內部顏色的漸層,漸層由android:startColor和android:endColor來實現,這個很好理解,另外一個很重要的標籤是漸層的角度android:angle,這個比較難,讓我們上手看看,
首先Button需要先引用shape.xml這個檔案,接下來我設定了四個比較典型的角度:0度,45度,90度,180度,看圖。
<gradient android:startColor="#000" //結束漸層顏色黑色 android:endColor="#FFF" //起始漸層顏色白色 android:angle="" //漸層角度 /> ![0度][2]![45度][3]![45度][4]![90度][5]![180度][6]漸層方向和角度的關係已經很明顯了。corners:本義是角落,在android裡角,就是四個角,這個屬性很簡單,只有半徑這個標籤需要記住 <!-- lang: java --> <!-- 組件圓角以及角半徑 --><!-- radius後邊屬性會覆蓋android:radius --> <corners android:radius="10dp" android:topLeftRadius="10dp" android:topRightRadius="20dp" android:bottomLeftRadius="30dp" //bottomLeftRadius和bottomRightRadius兩個屬性是顛倒的,這個需要注意 android:bottomRightRadius="40dp" /> stroke:就是border,邊框,搜到的文檔都叫描邊,雲裡霧裡啊看的,<!-- lang: java --><stroke android:color="#FF0000" //邊框顏色 android:width="4dp" //邊框寬度 android:dashWidth="4dp" //虛線邊框寬度 android:dashGap="10dp" //虛線邊框寬度 />
附贈一個外國人的黑技術~
android:shape妙用