AndroidUi(2)-圓角矩形

一.圓角矩形

Paste_Image.png
<?xml version="1.0" encoding="utf-8"?>
<!-- android:shape指定形狀類型,默認(rèn)為rectangle -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">    

<!-- solid設(shè)置填充色 -->    
<solid android:color="#36a3d9" />    

<!-- corners設(shè)置圓角-->    
<corners android:radius="10dp" />

</shape>

二.鏤空描邊矩形

Paste_Image.png
<?xml version="1.0" encoding="utf-8"?>
<!-- android:shape指定形狀類型 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">    

<!-- solid設(shè)置填充色 -->    
<solid android:color="#0036a3d9"  />  

  <!-- corners設(shè)置圓角-->    
<corners android:radius="10dp"  />    

  <!-- 設(shè)置邊框 -->    
<stroke  android:color="#36a3d9"  android:width="5dp"  />
</shape>

詳細(xì)屬性說(shuō)明
solid: 設(shè)置填充的顏色,只有android:color一個(gè)屬性
android:color 填充的顏色

padding: 設(shè)置內(nèi)間距
android:left 左內(nèi)間距
android:right 右內(nèi)間距
android:top 上內(nèi)間距
android:bottom 下內(nèi)間距

gradient: 設(shè)置漸變顏色,可以是線性漸變、輻射漸變、掃描性漸變
android:type 漸變的類型
linear 線性漸變,默認(rèn)
radial 放射漸變,設(shè)置該項(xiàng)時(shí),android:gradientRadius也必須設(shè)置
sweep 掃描性漸變
android:startColor 漸變開始的顏色
android:endColor 漸變結(jié)束的顏色
android:centerColor 漸變中間的顏色
android:angle 漸變的角度,線性漸變時(shí)才有效,必須是45的倍數(shù),0表示從左到右,90表示從下到上
android:centerX 漸變中心的相對(duì)X坐標(biāo),放射漸變時(shí)才有效,在0.0到1.0之間,默認(rèn)為0.5,表示在正中間
android:centerY 漸變中心的相對(duì)X坐標(biāo),放射漸變時(shí)才有效,在0.0到1.0之間,默認(rèn)為0.5,表示在正中間
android:gradientRadius 漸變的半徑,只有漸變類型為radial時(shí)才使用
android:useLevel 如果為true,則可在LevelListDrawable中使用

corners: 設(shè)置圓角,只適用于rectangle類型,可分別設(shè)置四個(gè)角不同半徑的圓角
android:radius 圓角半徑
android:topLeftRadius 左上角的半徑
android:topRightRadius 右上角的半徑
android:bottomLeftRadius 左下角的半徑
android:bottomRightRadius 右下角的半徑

stroke: 設(shè)置描邊,實(shí)線或虛線。
android:color 描邊顏色
android:width 描邊寬度
android:dashWidth 虛線的橫線長(zhǎng)度
android:dashGap 虛線的距離

代碼片段

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

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

  • 概述 今天我們來(lái)探究一下android的樣式。其實(shí),幾乎所有的控件都可以使用 background屬性去引用自定義...
    CokeNello閱讀 5,108評(píng)論 1 19
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,094評(píng)論 25 709
  • 記得剛開始學(xué)Android時(shí),看著自己完全用系統(tǒng)控件寫出的不忍直視的界面,對(duì)于如何做出不一樣的按鈕,讓它們?cè)诓煌瑺?..
    biloba閱讀 1,835評(píng)論 1 11
  • 原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明:轉(zhuǎn)載自Keegan小鋼 并標(biāo)明原文鏈接:http://keeganlee.me/post/a...
    于加澤閱讀 1,719評(píng)論 0 5
  • 煙伯離婚后經(jīng)常一個(gè)人搬個(gè)板凳滿臉兇悍地坐在大門口抽煙,時(shí)常和別人爭(zhēng)吵,每次經(jīng)過(guò)門口總是煙霧繚繞的。最近煙伯...
    慵慵懶懶閱讀 352評(píng)論 0 0

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