Android 自訂shape圓形按鈕

來源:互聯網
上載者:User

標籤:

Shape的屬性:

 

  •  solid

 

       描述:內部填充

       屬性:android:color 填充顏色

 

  •   size

 

       描述:大小

       屬性:

                 android:width 寬

                 android:height 高

 

  •  gradient

 

        描述:漸層色

        屬性:

                   android:startColor漸層起始顏色

                   android:endColor漸層結束顏色

                   android:centerColor漸層中間顏色

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

                   android:type 漸層類型:linear(線性)、radial(放射性,以開始色為中心)、sweep(掃描線式漸層)

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

                   android:grdientRadial漸層半徑,只有設定type為radial時,此值才生效

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

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

 

  • stroke

 

        描述:描邊

        屬性: 

                   android:width 描邊寬度

                   android:color 描邊顏色

                   android:dashwidth描邊樣式為虛線時的寬度,值為0時為實線,值大於0時為虛線

                   android:dashGap 描邊為虛線時,虛線之間的間隔

 

  • corners

 

        描述:圓角

        屬性:

                   android:radius 四個角半徑值

                   android:topLeftRadius左上方半徑值

                   android:topRightRadius右上方半徑值

                   android:bottomLeftRadius右下角半徑值

                   android:bottomRightRadius左下角半徑值

 

  • padding

 

        描述:內邊距

        屬性:

                   android:left 左內邊距

                   android:right 右內邊距

                   android:top 上內邊距

                   android:bottom 下內邊距

 

執行個體代碼

    <?xml version="1.0" encoding="utf-8"?>      <shape xmlns:android="http://schemas.android.com/apk/res/android" >                <corners android:radius="5dp" />                <size              android:height="30dp"              android:width="20dp" />                <gradient               android:startColor="#9933cc"              android:endColor="#aa66cc"              android:angle="90"              />                    <padding android:left="5dp"              android:right="5dp"              android:top="5dp"              android:bottom="5dp"/>            </shape>  

 

    <Button             android:id="@+id/btn"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_below="@+id/tv_test"             android:background="@drawable/btn_shape"             android:text="按鈕" />  

 

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.