Android 自定義shape圓形按鈕


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="按鈕" />  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM