[代码] [Java]代码
package com.tt.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class Love extends SurfaceView implements SurfaceHolder.Callback,Runnable
{
boolean mbloop = false;
SurfaceHolder mSurfaceHolder = null;
private Canvas canvas;
int minCount = 0;
int y = 50;
public Love(Context context)
{
super(context);
mSurfaceHolder = this.getHolder();
mSurfaceHolder.addCallback(this);
this.setFocusable(true);
this.setKeepScreenOn(true);
mbloop = true;
}
@Override
public void run()
{
// TODO Auto-generated method stub
while(mbloop)
{
try
{
Thread.sleep(200);
} catch (Exception e) {
// TODO: handle exception
}
synchronized (mSurfaceHolder)
{
draw();
}
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder)
{
// TODO Auto-generated method stub
new Thread(this).start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
// TODO Auto-generated method stub
mbloop = false;
}
private void draw()
{
canvas = mSurfaceHolder.lockCanvas();
try
{
if(mSurfaceHolder == null || canvas == null)
{
return;
}
if(minCount < 100)
{
minCount ++;
}
else
{
minCount = 0;
}
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
canvas.drawRect(0, 0,320,480,paint);
switch (minCount % 6)
{
case 0:
paint.setColor(Color.YELLOW);
break;
case 1:
paint.setColor(Color.BLUE);
break;
case 2:
paint.setColor(Color.GREEN);
break;
case 3:
paint.setColor(Color.RED);
break;
case 4:
paint.setColor(Color.argb(255, 255, 181, 216));
break;
case 5:
paint.setColor(Color.argb(255, 0, 255, 255));
break;
default:
break;
相关搜索(Beta)