引用:http://www.oschina.net/code/snippet_12_1257
[文件] xy_plot_4_Android_src.zip ~ 57KB 下载(127)
[代码] 绘制网格线的方法
01 |
public static void draw_the_grid(Canvas this_g, Vector these_labels) |
03 |
double rounded_max = 0.0 ; |
04 |
double rounded_min = 0.0 ; |
05 |
double rounded_max_temp; |
07 |
String[] cur_elt_array; |
08 |
int left_margin_d, right_margin_d; |
10 |
if ( draw_only_this_idx == - 1 ) |
11 |
curElt = these_labels.elementAt( 0 ); |
13 |
curElt = these_labels.elementAt(draw_only_this_idx); |
15 |
cur_elt_array = (String[])curElt; |
17 |
rounded_max = get_ceiling_or_floor (Double.parseDouble(cur_elt_array[ 2 ]) , true ); |
18 |
rounded_min = get_ceiling_or_floor (Double.parseDouble(cur_elt_array[ 3 ]) , false ); |
21 |
final Paint paint = new Paint(); |
22 |
paint.setTextSize( 15 ); |
24 |
left_margin_d = getCurTextLengthInPixels(paint, Double.toString(rounded_max)); |
28 |
int [] tmp_draw_sizes = { 2 + left_margin_d, 25 ,p_width - 2 - |
29 |
left_margin_d ,p_height - 25 - 5 }; |
30 |
drawSizes = tmp_draw_sizes; |
33 |
paint.setStyle(Paint.Style.FILL); |
34 |
paint.setColor(Color.WHITE ); |
37 |
this_g.drawRect(drawSizes[ 0 ], drawSizes[ 1 ],drawSizes[ 0 ]+ |
38 |
drawSizes[ 2 ], drawSizes[ 1 ]+ drawSizes[ 3 ] , paint); |
40 |
paint.setColor(Color.GRAY ); |
44 |
paint.setStyle(Paint.Style.STROKE); |
45 |
this_g.drawRect(drawSizes[ 0 ], drawSizes[ 1 ],drawSizes[ 0 ]+ |
46 |
drawSizes[ 2 ], drawSizes[ 1 ]+ drawSizes[ 3 ] , paint); |
48 |
for ( int i= 1 ; i < 5 ; i++) |
50 |
this_g.drawLine(drawSizes[ 0 ], drawSizes[ 1 ] + |
51 |
(i * drawSizes[ 3 ] / 5 ), drawSizes[ 0 ] + drawSizes[ 2 ], |
52 |
drawSizes[ 1 ] + (i * drawSizes[ 3 ] / 5 ), paint); |
53 |
this_g.drawLine(drawSizes[ 0 ]+ (i * drawSizes[ 2 ] / 5 ), |
54 |
drawSizes[ 1 ], drawSizes[ 0 ] + (i * drawSizes[ 2 ] / 5 ), |
55 |
drawSizes[ 1 ] + drawSizes[ 3 ], paint); |
59 |
print_axis_values_4_grid(this_g, cur_elt_array[ 1 ] , |
60 |
Double.toString(rounded_max) , Double.toString(rounded_min), |
61 |
cur_elt_array[ 0 ] , 2 , 0 ); |