Android ApiDemos樣本解析(65):Graphics->Drawable->S

來源:互聯網
上載者:User

除了在XML中使用Shape Drawable 資源外(如上例),也可以使用代碼來定義Shape Drawable,為Android中定義的Shape 類層次圖:

 

如果熟悉二維圖形開發,Path, Arc, Rect, Oval, RoundRect應該不陌生。 本例ShapeDrawable使用代碼來建立各種ShapeDrawable 並自訂一個Shape :MyShapeDrawable.

Android 中的 Shader 類同於其它平台的畫刷Brush (可以由單色畫刷,線性漸層畫刷,材質bitmap畫刷等)。

ShapeDrawable 中的幾個例子,只有第四個RoundRect 有些奇形怪狀。這是因為繪製這個RoundRectShape的Paint 使用了PathEffect:

[java] 
PathEffect pe = new DiscretePathEffect(10, 4);  
PathEffect pe2 = new CornerPathEffect(4);  
mDrawables[3].getPaint().setPathEffect(  
 new ComposePathEffect(pe2, pe)); 

PathEffect pe = new DiscretePathEffect(10, 4);
PathEffect pe2 = new CornerPathEffect(4);
mDrawables[3].getPaint().setPathEffect(
 new ComposePathEffect(pe2, pe));
 

PathEffect 可以影響Paint繪製圖形時幾何形體的形狀,Android提供了ComposePathEffect ,ConerPathEffect, DashPathEffec, DiscretePathEffect, PathDashPathEffect, SumPathEffect等幾種PathEffect。其中DiscretePathEffect可以隨機的位移原路徑位置,才有了本例的效果。

 
作者:mapdigit
 
 


 

聯繫我們

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