开发者社区> 问答> 正文

网页显示源代码,用什么才能使代码可折叠?

如下图:
展开前的折叠样子
screenshot
展开后的样子

 1 package com.example.android_olympiclogo;
 2 
 3 import android.view.View;
 4 import android.content.Context;
 5 import android.graphics.BitmapFactory;
 6 import android.graphics.Canvas;
 7 import android.graphics.Color;
 8 import android.graphics.Paint;
 9 import android.graphics.Paint.Style;
10 
11 public class MyView extends View {
12 
13     public MyView(Context context) {
14         super(context);
15     }
16     
17     public void onDraw(Canvas canvas) {
18         
19         Paint paint_blue = new Paint();                        //绘制蓝色的环
20         paint_blue.setColor(Color.BLUE);
21         paint_blue.setStyle(Style.STROKE);
22         paint_blue.setStrokeWidth(10);        
23         canvas.drawCircle(110,150,60,paint_blue);
24         
25         Paint paint_yellow = new Paint();                //绘制黄色的环
26         paint_yellow.setColor(Color.YELLOW);
27         paint_yellow.setStyle(Style.STROKE);
28         paint_yellow.setStrokeWidth(10);
29         canvas.drawCircle((float)175.5, 210, 60, paint_yellow);
30         
31         Paint paint_black = new Paint();                   //绘制黑色的环
32         paint_black.setColor(Color.BLACK);
33         paint_black.setStyle(Style.STROKE);
34         paint_black.setStrokeWidth(10);
35         canvas.drawCircle(245, 150, 60, paint_black);
36         
37         Paint paint_green = new Paint();                  //绘制绿色的环
38         paint_green.setColor(Color.GREEN);
39         paint_green.setStyle(Style.STROKE);
40         paint_green.setStrokeWidth(10);
41         canvas.drawCircle(311, 210, 60, paint_green);
42         
43         Paint paint_red = new Paint();                       //绘制红色的环
44         paint_red.setColor(Color.RED);
45         paint_red.setStyle(Style.STROKE);
46         paint_red.setStrokeWidth(10);
47         canvas.drawCircle(380, 150, 60, paint_red);
48         
49         Paint paint_string = new Paint();                   //绘制字符串
50         paint_string.setColor(Color.BLUE);
51         paint_string.setTextSize(20);
52         canvas.drawText("Welcome to Beijing", 245, 310, paint_string);
53         
54         Paint paint_line = new Paint();                       //绘制直线
55         paint_line.setColor(Color.BLUE);
56         canvas.drawLine(240, 310, 425, 310, paint_line);
57         
58         Paint paint_text = new Paint();                      //绘制字符串
59         paint_text.setColor(Color.BLUE);
60         paint_text.setTextSize(20);
61         canvas.drawText("北京欢迎您", 275, 330, paint_text);
62         
63         //绘制福娃图片
64         canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.fuwa), 35, 340, paint_line);
65     }
66 }

screenshot

展开
收起
杨冬芳 2016-06-12 12:03:26 2689 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载