android中的 shape

來源:互聯網
上載者:User

shape 可以實現一些你想要的效果, 比如有時候 你在一個  button 獲得焦點,按下 ,時要改變圖片 以讓客戶有更好的體驗感覺。

shape 就可以改變這些  控制項的一些 屬性, 可以說 讓你在一個小項目中實現 獲得焦點,按下 統一的效果和 風格吧, 而且這樣超級方便呢。

在 你的 drawable檔案夾下面    建立1個xml檔案,比如    selector.xml 

shape裡面有這麼幾個屬性,其實很簡單:

  
  <shape>   
            <solid android:color=""/>    實心屬性: 什麼顏色

            <gradient

                android:startColor=""    漸層屬性: 1.開始顏色         

                android:endColor=""                2.結束顏色   

                android:angle="90" />                    3.angle: 漸層的角度 必須為45度的倍數

         //漸層平常預設是 線性漸層    android:type="linear",

        // 想要變成 放射狀漸層    android:type="radial",放射狀漸層需要指定半徑android:gradientRadius="30"。


            <stroke                              描邊屬性: 

                android:width="3dp"                        1.描邊的寬度

                android:dashWidth="6dp"                    2.表示橫線的寬度
                android:dashGap="3dp"                      3.表示隔開的距離

                android:color="" />                        4.描邊的顏色

        

             <corners                             圓角屬性:
                android:topRightRadius="20dp"                右上方
                android:bottomLeftRadius="20dp"              右下角
                android:topLeftRadius="1dp"                  左上方
                android:bottomRightRadius="0dp"              左下角
                  />

            <padding

                android:left="10dp"

                android:top="10dp"

                android:right="10dp"

                android:bottom="10dp" />

        </shape>

在  selector.xml   中 的  平常, 獲得焦點 , 按下時, 進行設定就可以看到不同的效果了

<selector

    <item android:state_pressed="true" >

        <shape>

        </shape>

    </item>

    <item android:state_focused="true" >

        <shape>

        </shape>

    </item>

</selector>

好了,也就這麼些了, 想看效果的話趕緊試試吧。。



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.