Android 简单2D绘图

来源:互联网 发布:51信用卡工作 知乎 编辑:程序博客网 时间:2024/05/16 07:32

因为24点程序,需要自己绘制数字,忽然发现自己多线程方面不是很熟悉,想练下,最好能一个线程画圆,一个线程画直线,后面通过查了下资料,据说是不能实现,就用了别的方法

package com.example.cout24;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.RectF;import android.view.View;public class BackView extends View{private static int lineend=0;private static float startAngle;   MainActivity M;public BackView(Context context) {super(context);M=(MainActivity)context;// TODO Auto-generated constructor stub}  protected void onDraw(Canvas canvas){  Paint BlackP=new Paint();  BlackP.setColor(getResources().getColor(R.color.Black  ));  BlackP.setStyle(Paint.Style.STROKE);  BlackP.setStrokeWidth(getHeight()/30);  Paint NavyP=new Paint();  NavyP.setColor(getResources().getColor(R.color.Navy));  NavyP.setStyle(Paint.Style.STROKE);  NavyP.setStrokeWidth(getHeight()/30);  RectF rf=new RectF(getWidth()/3, getHeight()/10*5, getWidth()/4*3,getHeight()/10*9);  canvas.drawLine(0, getHeight()/5, lineend,getHeight()/5, BlackP);  canvas.drawArc(rf, 0, startAngle, true, NavyP);  if(lineend<getWidth()||startAngle<360){ lineend+=20;  if(startAngle<360){  startAngle+=10;  }  try {Thread.sleep(100);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}  invalidate();  return;  }   M.play();//  canvas.drawRect(getWidth()/9,getHeight()/8, getWidth()/2,getHeight()/100*44,BlackP);  }}

我想把这段绘画的动画放在程序主界面前,跳转方面不知道规范不规范。

protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);BackView b=new BackView(this);setContentView(b); Music.play(this, R.raw.title);}

 先用MainActivity setContentview调用动画,BackView存放着M的context,动画播放完后,再调用M.play(),进入主界面。


0 0
原创粉丝点击