成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Android開發速成簡潔教程十五:RadioButton及路徑繪制

移動開發 Android
這個例子是繪制多邊形,多義形和路徑,采用單選鈕RadioButton來選擇Polys 和Path示例:UI設計為上部分用來顯示繪圖內容,下部分為兩個單選按鈕 Polys ,Path。這樣layout就和main.xml 不一樣,main.xml只含一個com.pstreets.graphics2d.GuidebeeGraphics2DView。

這個例子是繪制多邊形,多義形和路徑,采用單選鈕RadioButton來選擇Polys 和Path示例:

UI 設計為 上部分用來顯示繪圖內容,下部分為兩個單選按鈕 Polys ,Path。這樣layout就和main.xml 不一樣,main.xml只含一個com.pstreets.graphics2d.GuidebeeGraphics2DView。因此需在 res\layout下新建一個polys.xml:

  1. <?xml version=”1.0″ encoding=”utf-8″?> 
  2. <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” 
  3.     android:orientation=”vertical” 
  4.     android:background=”@drawable/white” 
  5.  android:layout_width=”fill_parent” 
  6.  android:layout_height=”fill_parent”> 
  7.     <com.pstreets.graphics2d.GuidebeeGraphics2DView 
  8.      android:id=”@+id/graphics2dview” 
  9.      android:layout_weight=”1″ 
  10.      android:layout_width=”fill_parent” 
  11.      android:layout_height=”wrap_content”/> 
  12.  <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” 
  13.   android:layout_width=”wrap_content” android:layout_height=”wrap_content” 
  14.   android:orientation=”horizontal” 
  15.    
  16.   > 
  17.   <RadioGroup 
  18.      android:layout_width=”wrap_content” 
  19.      android:orientation=”horizontal” 
  20.      android:textSize=”20dp” 
  21.      android:layout_height=”wrap_content”> 
  22.    <RadioButton android:text=”Polys” 
  23.        android:id=”@+id/radioPolys” 
  24.     android:layout_width=”wrap_content” 
  25.     android:textColor=”@color/black” 
  26.     android:checked=”true” 
  27.     android:layout_height=”wrap_content”> 
  28.    </RadioButton> 
  29.    <RadioButton android:text=”Path” 
  30.         android:id=”@+id/radioPath” 
  31.     android:layout_width=”wrap_content” 
  32.     android:textColor=”@color/black” 
  33.     android:layout_height=”wrap_content”> 
  34.    </RadioButton> 
  35.   </RadioGroup> 
  36.  </LinearLayout> 
  37.  
  38. </LinearLayout> 

RadioButton 需包含在RadioGroup中做為一個分組,這里將Polys 設為選中。

定義好Layout資源后,修改 Path.java

  1. private RadioButton radioPoly; 
  2.     private RadioButton radioPath;    
  3.     public void onCreate(Bundle savedInstanceState) { 
  4.      super.onCreate(savedInstanceState); 
  5.      setContentView(R.layout.polys); 
  6.      graphic2dView 
  7.       = (GuidebeeGraphics2DView) 
  8.         findViewById(R.id.graphics2dview); 
  9.      radioPath = (RadioButton) findViewById(R.id.radioPath); 
  10.      radioPoly = (RadioButton) findViewById(R.id.radioPolys); 
  11.      radioPath.setOnClickListener(this); 
  12.      radioPoly.setOnClickListener(this); 
  13.     } 

應為需要處理按鍵消息,所以定義了兩個RadioButton對象,可以通過findViewById獲取實例。因為兩個RadioButton這里采用 同樣的處理方法,可以讓Path實現OnClickListener ,即:public class Path extends Graphics2DActivity   implements OnClickListener。完整代碼如下:

  1. 1   public class Path extends Graphics2DActivity 
  2. 2      implements OnClickListener { 
  3. 3     
  4. 4       private RadioButton radioPoly; 
  5. 5       private RadioButton radioPath; 
  6. 6     
  7. 7       public void onCreate(Bundle savedInstanceState) { 
  8. 8           super.onCreate(savedInstanceState); 
  9. 9           setContentView(R.layout.polys); 
  10. 10          graphic2dView 
  11. 11           = (GuidebeeGraphics2DView) 
  12. 12             findViewById(R.id.graphics2dview); 
  13. 13          radioPath = (RadioButton) findViewById(R.id.radioPath); 
  14. 14          radioPoly = (RadioButton) findViewById(R.id.radioPolys); 
  15. 15          radioPath.setOnClickListener(this); 
  16. 16          radioPoly.setOnClickListener(this); 
  17. 17      } 
  18. 18    
  19. 19      @Override 
  20. 20      protected void drawImage() { 
  21. 21          if (radioPoly.isChecked()) { 
  22. 22              drawPolys(); 
  23. 23          } else { 
  24. 24              drawPaths(); 
  25. 25          } 
  26. 26          graphic2dView.refreshCanvas(); 
  27. 27    
  28. 28      } 
  29. 29    
  30. 30      @Override 
  31. 31      public void onClick(View view) { 
  32. 32          drawImage(); 
  33. 33      } 
  34. 34    
  35. 35      private void drawPaths() { 
  36. 36          AffineTransform mat1; 
  37. 37    
  38. 38          // The path. 
  39. 39          com.mapdigit.drawing.geometry.Path path; 
  40. 40    
  41. 41          // Colors 
  42. 42          Color redColor = new Color(0x96ff0000true); 
  43. 43          Color greenColor = new Color(0xff00ff00); 
  44. 44          Color blueColor = new Color(0x750000fftrue); 
  45. 45    
  46. 46          String pathdata 
  47. 47             = "M 60 20 Q -40 70 60 120 Q 160 70 60 20 z"
  48. 48          mat1 = new AffineTransform(); 
  49. 49          mat1.translate(3040); 
  50. 50          mat1.rotate(-30 * Math.PI / 180.0); 
  51. 51          path = com.mapdigit.drawing.geometry.Path.fromString(pathdata); 
  52. 52          // Clear the canvas with white color. 
  53. 53          graphics2D.clear(Color.WHITE); 
  54. 54    
  55. 55          graphics2D.setAffineTransform(new AffineTransform()); 
  56. 56          SolidBrush brush = new SolidBrush(greenColor); 
  57. 57          graphics2D.fill(brush, path); 
  58. 58          graphics2D.setAffineTransform(mat1); 
  59. 59    
  60. 60          brush = new SolidBrush(blueColor); 
  61. 61          com.mapdigit.drawing.Pen pen 
  62. 62             = new com.mapdigit.drawing.Pen(redColor, 5); 
  63. 63          graphics2D.setPenAndBrush(pen, brush); 
  64. 64          graphics2D.draw(null, path); 
  65. 65          graphics2D.fill(null, path); 
  66. 66    
  67. 67      } 
  68. 68    
  69. 69      private void drawPolys() { 
  70. 70          AffineTransform mat1; 
  71. 71    
  72. 72          // Colors 
  73. 73          Color redColor = new Color(0x96ff0000true); 
  74. 74          Color greenColor = new Color(0xff00ff00); 
  75. 75          Color blueColor = new Color(0x750000fftrue); 
  76. 76    
  77. 77          Polyline polyline; 
  78. 78          Polygon polygon; 
  79. 79          Polygon polygon1; 
  80. 80    
  81. 81          String pointsdata1 
  82. 82          = "59,45,95,63,108,105,82,139,39,140,11,107,19,65"
  83. 83          mat1 = new AffineTransform(); 
  84. 84          mat1.translate(3040); 
  85. 85          mat1.rotate(-30 * Math.PI / 180.0); 
  86. 86          polyline = new Polyline(); 
  87. 87          polygon = new Polygon(); 
  88. 88          polygon1 = new Polygon(); 
  89. 89          Point[] points = Point.fromString(pointsdata1); 
  90. 90          for (int i = 0; i < points.length; i++) { 
  91. 91              polyline.addPoint(points[i].x, points[i].y); 
  92. 92              polygon.addPoint(points[i].x, points[i].y); 
  93. 93              polygon1.addPoint(points[i].x, points[i].y); 
  94. 94          } 
  95. 95          // Clear the canvas with white color. 
  96. 96          graphics2D.clear(Color.WHITE); 
  97. 97    
  98. 98          graphics2D.setAffineTransform(new AffineTransform()); 
  99. 99          SolidBrush brush = new SolidBrush(greenColor); 
  100. 100         graphics2D.fillPolygon(brush, polygon); 
  101. 101         graphics2D.setAffineTransform(mat1); 
  102. 102   
  103. 103         brush = new SolidBrush(blueColor); 
  104. 104         com.mapdigit.drawing.Pen pen 
  105. 105            = new com.mapdigit.drawing.Pen(redColor, 5); 
  106. 106         graphics2D.setPenAndBrush(pen, brush); 
  107. 107         graphics2D.fillPolygon(null, polygon1); 
  108. 108         graphics2D.drawPolyline(null, polyline); 
  109. 109   
  110. 110     } 
  111. 111   
  112. 112 } 

責任編輯:閆佳明 來源: imobilebbs
相關推薦

2013-12-26 15:10:08

Android開發應用和框架Linux 內核

2013-12-26 15:43:07

Android開發Android應用Activities

2013-12-27 13:00:30

Android開發Android應用Context Men

2013-12-26 15:18:09

Android開發安裝開發環境

2013-12-27 15:11:17

Android開發訪問Internet繪制在線地圖

2013-12-27 14:05:22

Android開發Android應用Dialog

2013-12-27 14:16:43

Android開發Android應用線程

2013-12-27 14:34:46

Android開發Android應用短信觸發示例

2013-12-26 16:33:24

Android開發Android應用引路蜂二維圖形繪制

2013-12-27 16:06:10

Android開發Android應用發布應用

2013-12-26 15:46:30

Android開發Android應用用戶界面設計

2013-12-26 15:34:19

Android開發Android應用基本概念

2013-12-26 16:59:12

Android開發Android應用數據綁定Data Bi

2013-12-27 12:51:44

Android開發Android應用引路蜂

2013-12-27 13:49:22

Android開發Android應用Button

2013-12-26 16:24:13

Android開發Android應用Intents

2013-12-27 15:31:26

Android開發Android應用資源Resources

2013-12-26 16:46:21

2013-12-26 17:08:36

Android開發Android應用自定義Adapter顯

2013-12-27 14:10:36

Android開發Android應用Transform
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 97av在线| 香蕉大人久久国产成人av | 欧美色综合 | 日韩aⅴ视频 | 黄色三级免费网站 | 欧美精品福利 | 玖玖精品视频 | 国产综合精品 | 日韩中文字幕在线观看视频 | 国产毛片久久久久久久久春天 | 亚洲人免费视频 | 在线区| 日韩福利在线 | 成人免费精品视频 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 | 欧美jizzhd精品欧美巨大免费 | 日本免费一区二区三区四区 | 中文字幕一级 | 国产丝袜一区二区三区免费视频 | 国产精品视频一区二区三区不卡 | 国产视频一区二区三区四区五区 | 国产农村妇女毛片精品久久麻豆 | 国产精品一区二区在线播放 | 男女在线免费观看 | 九九九色| 久久久久久国产精品免费免费 | 亚洲不卡在线观看 | 蜜桃视频一区二区三区 | 亚洲精品一区中文字幕乱码 | 欧产日产国产精品99 | av黄在线观看 | 婷婷综合 | 久久久亚洲 | 精品国产一区二区三区久久 | 中文在线一区二区 | 亚洲黄色在线 | 国产福利二区 | 久久成人免费 | 欧美日韩一区二区在线观看 | 亚洲狠狠| 华人黄网站大全 |