Android下基於XML的Graphics

來源:互聯網
上載者:User

原文地址:http://qq361119908.iteye.com/blog/656281

 

以前作圖一般有兩種方式:1、UI把圖形設計好我們直接貼。2對於那些簡單的圖形,如矩形、扇形這樣的圖形,一般的系統的API會提供這樣的介面。但是在Android下,有第三種畫圖方式,介於二者之間,結合二者的長處。如下的代碼:
    <item android:id="@android:id/secondaryProgress">        <clip>            <shape>                <corners android:radius="5dip" />                <gradient                        android:startColor="#0055ff88"                        android:centerColor="#0055ff00"                        android:centerY="0.75"                        android:endColor="#00320077"                        android:angle="270"                />            </shape>        </clip>    </item>
這是一個Progress的style裡面的代碼,描述的是進度條的未達到的圖形。原本以為這是一個圖片,後來仔細的跟蹤代碼,發現居然是xml。像這種shape corners gradient等等這還是第一次碰到。shape 表示是一個圖形,corners表示是有半徑為5像素的圓角,gradient表示一個漸層。這樣作圖簡單明了,並且可以做出要求很好的圖形,並且節省資源。
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">    <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF"            android:angle="270"/>    <padding android:left="50dp" android:top="20dp"            android:right="7dp" android:bottom="7dp" />    <corners android:radius="8dp" />   </shape>
屬性 android:shape="rectangle"  表示 預設的是長方形。

gradient  產生色彩坡形 ,屬性 android:angle 表示從哪個角度開始變,貌似只有90的整數倍可以 。

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">    <solid android:color="#ff4100ff"/>    <stroke android:width="2dp" android:color="#ee31ff5e"            android:dashWidth="3dp" android:dashGap="2dp" />    <padding android:left="7dp" android:top="7dp"            android:right="7dp" android:bottom="7dp" />    <corners android:radius="6dp" /></shape>

    #ff4100ff藍色  

    #ff4100ff綠色
     <solid android:color="#ff4100ff"/>實心的 填充裡面
     <stroke 描邊,採用那樣的方式將外形輪廓線畫出來

      android:dashWidth="3dp" android:dashGap="2dp" 預設值為0
      android:width="2dp" android:color="#FF00ff00" 筆的粗細, 
      android:dashWidth="5dp" android:dashGap="5dp" 實現“- - -”這樣的效果。      dashWidth指的是一條小橫線的寬度 
      android:dashGap 指的是小橫線與小橫線的間距。

相關文章

聯繫我們

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