首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android 画图有关问题

2012-05-08 
android画图问题Java codepackage my.pathimport android.app.Activityimport android.content.Context

android 画图问题

Java code
package my.path;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.graphics.Path.Direction;import android.os.Bundle;import android.view.View;import android.widget.*;public class SharpAndroidActivity extends Activity {    private static String text = "The school's website is http://www.hytc.edu.cn";    LinearLayout lay=null;    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(new GraphicsView(this));    }    static public class GraphicsView extends View {        public GraphicsView(Context context) {            super(context);        }        protected void onDraw(Canvas canvas) {            canvas = new Canvas();            canvas.drawColor(Color.BLUE);            Paint paint = new Paint();            paint.setColor(Color.LTGRAY);            Path cir = new Path();            cir.addCircle(150, 150, 100, Direction.CCW);            canvas.drawPath(cir, paint);            canvas.drawText(text, 0, 20, paint);                    canvas.drawPath(cir, paint);        }    }}画图显示不出来啊  为什么啊  ?


[解决办法]
protected void onDraw(Canvas canvas) {
canvas = new Canvas();
canvas.drawColor(Color.BLUE);
Paint paint = new Paint();
paint.setColor(Color.LTGRAY);
Path cir = new Path();
cir.addCircle(150, 150, 100, Direction.CCW);
canvas.drawPath(cir, paint);
canvas.drawText(text, 0, 20, paint);
canvas.drawPath(cir, paint);
}

去掉第一句canvas = new Canvas();
你用的canvas是新new出来的, 怎么会显示呢...

热点排行