Android shape的使用

來源:互聯網
上載者:User

標籤:android   http   io   color   ar   使用   檔案   on   art   

一、在res/drawable檔案夾下建立一個名為gradient_box的xml檔案:

<?xml version="1.0" encoding="utf-8"?>

<!--

shape drawable xml檔案中定義的一個幾何圖形,定義在res/drawable/目錄下,檔案名稱filename稱為訪問的資源ID

在代碼中通過R.drawable.filename進行訪問,在xml檔案中通過@[package:]drawable/filename進行訪問。

-->

<!--

android:shape=["rectangle" "oval" "line" "ring"]

shape的形狀,預設為矩形,可以設定為矩形(rectangle)、橢圓形(oval)、線性形狀(line)、環形(ring)

下面的屬性只有在android:shape="ring時可用:

android:innerRadius 尺寸,內環的半徑。

android:innerRadiusRatio 浮點型,以環的寬度比率來表示內環的半徑,

例如,如果android:innerRadiusRatio,表示內環半徑等於環的寬度除以5,這個值是可以被覆蓋的,預設為9.

android:thickness 尺寸,環的厚度

android:thicknessRatio 浮點型,以環的寬度比率來表示環的厚度,例如,如果android:thicknessRatio="2",

那麼環的厚度就等於環的寬度除以2。這個值是可以被android:thickness覆蓋的,預設值是3.

android:useLevel boolean值,如果當做是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 顏色值 結束顏色

android:centerColor 整型 漸層中間顏色,即開始顏色與結束顏色之間的顏色

android:angle 整型 漸層角度(PS:當angle=0時,漸層色是從左向右。 然後逆時針方向轉,當angle=90時為從下往上。angle必須為45的整數倍)

android:type ["linear" "radial" "sweep"] 漸層類型(取值:linear、radial、sweep)

linear 線性漸層,這是預設設定

radial 放射性漸層,以開始色為中心。

sweep 掃描線式的漸層。

android:useLevel ["true" "false"] 如果要使用LevelListDrawable對象,就要設定為true。設定為true無漸層。false有漸層色

android:gradientRadius 整型 漸層色半徑.當 android:type="radial" 時才使用。單獨使用 android:type="radial"會報錯。

android:centerX 整型 漸層中心X點座標的相對位置

android:centerY 整型 漸層中心Y點座標的相對位置

-->

<gradient

android:startColor="#FFFF0000"

android:endColor="#80FF00FF"

android:angle="45"

/>

<!--

內邊距,即內容與邊的距離

android:left 整型 左內邊距

android:top 整型 上內邊距

android:right 整型 右內邊距

android:bottom 整型 下內邊距

-->

<padding

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp"

/>

<!--

size 大小

android:width 整型 寬度

android:height 整型 高度

-->

<size

android:width="600dp"

/>

<!--

內部填充

android:color 顏色值 填充顏色

-->

<solid

android:color="#ffff9d77"

/>

<!--

描邊

android:width 整型 描邊的寬度

android:color 顏色值 描邊的顏色

android:dashWidth 整型 表示描邊的樣式是虛線的寬度, 值為0時,表示為實線。值大於0則為虛線。

android:dashGap 整型 表示描邊為虛線時,虛線之間的間隔 即“ - - - - ”

-->

<stroke

android:width="2dp"

android:color="#dcdcdc"

/>

</shape>

Android shape的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.