Android中的Shape屬性

<?xml version="1.0" encoding="utf-8"?>
<!--
    shape drawable xml文件中定義的一個幾何圖形,
    定義在res/drawable/目錄下,文件名filename稱為訪問的資源ID
    在代碼中通過R.drawable.filename進(jìn)行訪問,
    在xml文件中通過@[package:]drawable/filename進(jìn)行訪問。
-->
<!--
    android:shape = "rectangle|oval|line|ring"
    shape的形狀,默認(rèn)為矩形(rectangle),橢圓形(oval),線性形狀(line),環(huán)形(ring)
    下面的屬性只有在android:shape="ring時可用:
    android:innerRadius     尺寸,內(nèi)環(huán)的半徑。
    android:innerRadiusRatio    浮點(diǎn)型,以環(huán)的寬度比率來表示內(nèi)環(huán)的半徑,
    例如,如果android:innerRadiusRatio,表示內(nèi)環(huán)半徑等于環(huán)的寬度除以5,這個值是可以被覆蓋的,默認(rèn)為9.
    android:thickness  尺寸,環(huán)的厚度
    android:thicknessRatio  浮點(diǎn)型,以環(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:radius             整型 半徑
            android:topLeftRadius       整型 左上角半徑
            android:topRightRadius      整型 右上角半徑
            android:bottomLeftRadius    整型 左下角半徑
            android:bottomRightRadius   整型 右下角半徑
         -->
    <corners
        android:radius="8dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="15dp"
        android:bottomLeftRadius="20dp"
        android:bottomRightRadius="25dp"
        />

    <!--
        漸變色
        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" 時才使用。單獨(dú)使用 android:type="radial"會報錯。
        android:centerX     整型      漸變中心X點(diǎn)坐標(biāo)的相對位置
        android:centerY     整型      漸變中心Y點(diǎn)坐標(biāo)的相對位置
   -->
    <gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"
        />

    <!--
        內(nèi)邊距,即內(nèi)容與邊的距離
        android:left    整型 左內(nèi)邊距
        android:top     整型 上內(nèi)邊距
        android:right   整型 右內(nèi)邊距
        android:bottom  整型 下內(nèi)邊距
      -->
    <padding
        android:left="10dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp"
        />

    <!--
        size 大小
        android:width   整型 寬度
        android:height  整型 高度
    -->
    <size
        android:width="600dp"
        />

    <!--
        內(nèi)部填充
        android:color   顏色值 填充顏色
    -->
    <solid
        android:color="#ffff9d77"
        />

    <!--
        描邊
        android:width       整型  描邊的寬度
       android:color        顏色值     描邊的顏色
       android:dashWidth    整型  表示描邊的樣式是虛線的寬度, 值為0時,表示為實(shí)線。值大于0則為虛線。
       android:dashGap      整型  表示描邊為虛線時,虛線之間的間隔 即“ - - - - ”
    -->
    <stroke
        android:width="2dp"
        android:color="#dcdcdc"/>
</shape>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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