shape 標(biāo)簽使用詳解


 <!-- 
    android:shape=["rectangle" | "oval" | "line" | "ring"]
    shape的形狀,默認(rèn)為矩形,可以設(shè)置為矩形(rectangle)、橢圓形(oval)、線(line)、環(huán)形(ring)

    下面的屬性只有在android:shape="ring時可用:
    android:innerRadius           內(nèi)環(huán)的半徑。
    android:innerRadiusRatio    浮點型,以環(huán)的寬度比率來表示內(nèi)環(huán)的半徑,
    例如,如果android:innerRadiusRatio,表示內(nèi)環(huán)半徑等于環(huán)的寬度除以5,這個值是可以被覆蓋的,默認(rèn)為9.

    android:thickness              環(huán)的厚度
    android:thicknessRatio      浮點型,以環(huán)的寬度比率來表示環(huán)的厚度,例如,如果android:thicknessRatio="2",
    那么環(huán)的厚度就等于環(huán)的寬度除以2。這個值是可以被android:thickness覆蓋的,默認(rèn)值是3.
    
    android:useLevel            boolean值,如果當(dāng)做是LevelListDrawable使用時值為true,否則為false.
  -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" >
    <!--寬度和高度 
        android:width   整型 寬度
        android:height  整型 高度
    -->
    <size
        android:width="50dp"
        android:height="50dp"/>

    <!--圓角
        android:radius                    整型 半徑
        android:topLeftRadius           整型 左上角半徑
        android:topRightRadius               整型 右上角半徑
        android:bottomLeftRadius           整型 左下角半徑
        android:bottomRightRadius         整型 右下角半徑
    -->
    <corners
        android:radius="10dp"/><!-- 設(shè)置圓角半徑,可以分別設(shè)置4個角 -->
    
    <!--漸變,這個設(shè)置之后一般就不要設(shè)置solid填充色了
        android:startColor  顏色值     起始顏色
        android:endColor    顏色值     結(jié)束顏色
        android:centerColor 整型       漸變中間顏色,即開始顏色與結(jié)束顏色之間的顏色
        android:angle       整型       
     漸變角度(PS:當(dāng)angle=0時,漸變色是從左向右。 然后逆時針方向轉(zhuǎn),當(dāng)angle=90時為從下往上。angle必須為45的整數(shù)倍)

        android:type        ["linear" | "radial" | "sweep"] 漸變類型(取值:linear、radial、sweep)
                            linear 線性漸變,這是默認(rèn)設(shè)置
                            radial 放射性漸變,以開始色為中心。
                            sweep 掃描線式的漸變。

        android:useLevel     ["true" | "false"]              
     如果要使用LevelListDrawable對象,就要設(shè)置為true。設(shè)置為true無漸變。false有漸變色

        android:gradientRadius 整型   
        漸變色半徑.當(dāng) android:type="radial" 時才使用。單獨使用 android:type="radial"會報錯。

        android:centerX      整型     漸變中心X點坐標(biāo)的相對位置
        android:centerY      整型     漸變中心Y點坐標(biāo)的相對位置
    -->
    <gradient
        android:startColor="@android:color/white"
        android:centerColor="@android:color/black"
        android:endColor="@android:color/black"
        android:useLevel="true"
        android:angle="45"
        android:type="radial"
        android:centerX="0"
        android:centerY="0"
        android:gradientRadius="90"/>
    
    <!-- 間隔
        內(nèi)邊距,即內(nèi)容與邊的距離 
        android:left        整型 左內(nèi)邊距
        android:top        整型 上內(nèi)邊距
        android:right      整型 右內(nèi)邊距
        android:bottom   整型 下內(nèi)邊距
    -->
    <padding
        android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp"/>
    
    <!--填充 
        android:color   顏色值 填充顏色
    -->
    <solid
        android:color="@android:color/white"/><!-- 填充的顏色 -->
    
    <!--描邊 
        android:width          整型      描邊的寬度
        android:color           顏色值    描邊的顏色
        android:dashWidth   整型      表示描邊的樣式是虛線的寬度, 值為0時,表示為實線。值大于0則為虛線。
        android:dashGap     整型      表示描邊為虛線時,虛線之間的間隔 即“ - - - - ”
    -->
    <stroke
        android:width="1dp" <!-- 邊框?qū)挾?-->
        android:color="@android:color/black"
        android:dashWidth="1dp"
        android:dashGap="2dp"/>
    
</shape> 
image.png

掃描漸變:

<!-- 圓形內(nèi)部填充-掃描漸變 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel="true">

    <size
        android:width="@dimen/shape_size"
        android:height="@dimen/shape_size" />

    <!-- sweep類型angle,gradientRadius無效,centerX, centerY是百分百(0-1) -->
    <gradient
        android:centerX="0.5"
        android:centerY="0.6"
        android:startColor="#ffff0000"
        android:centerColor="#80ff0000"
        android:endColor="#20ff0000"
        android:gradientRadius="20dp"
        android:type="sweep" />

</shape>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容