android shape 資源的學習筆記



    shape文件是位於res/drawable/filename.xml文件下的形狀定義工具。可以用來作爲按鈕背景或者作爲分割線

下面是摘自官方文檔的shape XML文檔的屬性總攬。

   shape可設置的形狀

rectangle:矩形。最常用的形狀

oval:橢圓

line:直線。通常用於分割線的時候

ring:環形。

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


   shape包含的屬性

1、corners

這個僅僅用於當<shape>標籤中的android:shape屬性爲rectangle的時候使用。可以使矩形邊角呈一定弧度

另外,topLeftRadius等會覆蓋設置的總的radius

這是設置radius爲20dp,topLeftRadius和topRightRadius設置爲80dp的結果。(爲了突出效果,所以醜了點)


2、gradient

設置漸變效果

android:type(漸變類型):分爲linear(線性),radial(輻射),sweep(掃描式)

·radial和sweep兩種方式都需要設置radientRadius

·linear類型可以設置android:angle屬性,來改變線性漸變的角度。其值必須是45的倍數

centerX:設置開始漸變的X座標,(範圍0-1.0)

centerY:設置開始漸變的Y座標,(範圍0-1.0)


3、padding

內邊距


4、size

形狀大小


5、solid

填充色,形狀的顏色


6、stroke

形狀的描邊

當同時設置以下兩個屬性時,描邊則爲虛線表示

android:dashGap 描邊的間隔寬度

android:dashWidth 虛線的寬度

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