建立 .xml 檔
 |
res 資料夾新增 Drawable Resource File |
 |
Root element 選擇 layer-list |
 |
輸入 File name 後點選 OK |
前言
介紹基本 Drawable 的一些設定,主要是參考官方的文件。
包含 corner, gradient, padding, solid, size 等
網址連結 : https://developer.android.com/guide/topics/resources/drawable-resource#LevelList
基本介紹
使用到底下的設定時,要特別注意 shape 類型,否則設定錯誤會沒有效果
 |
可以在 shape 內設定 |
CORNER
根據官方的資料,只能使用在 rectangle
建立基本圖形,使用 rectangle
 |
xml 效果 |
設定 4 個角為圓角
 |
選擇 radius |
 |
設定 radius = 35 dp 效果 |
單獨設定某個角
 |
設定左上角效果 |
備註 : 同時設定 radius及任何一個單獨的角,radius 的效果會被覆蓋
 |
文件說明 |
STROKE
簡單的寬度及顏色設定
支援虛線
解釋 dashGap 及 dashWidth 分別代表的意思
GRADIENT
 |
可以使用的屬性 |
 |
官網給的 Sample 分別給了角度, 開始及結束的顏色 |
SOLID
只有單一個屬性
 |
設定顏色 |
備註 : 與 gradient 同時存在時,程式碼靠後的會被執行
 |
移動 gradient 位置 與 solid 交換位置 |
PADDING
 |
上下左右可以設定 |
要注意官網的描述
 |
沒有任何設定時,TextView 置中 |
 |
已設定距離 bottom 500dp 設定 backgroud 為 sample_background |
設定與底部距離 500dp ,從. xml 檔中看不出效果,但上方 TextView 位置已經上移
留言
張貼留言