public class TestView extends View implements Runnable {
Bitmap m_bitQQ;
Bitmap m_bitCanvas;
Canvas m_canvas;
Paint m_paint;
public TestView(Context context) {
super(context);
m_bitQQ = ((BitmapDrawable)getResources().
getDrawable(R.mipmap.img1)).getBitmap();
DisplayMetrics dm = new DisplayMetrics();
WindowManager wm =(WindowManager)context.
getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(dm);
m_bitCanvas = Bitmap.createBitmap(dm.widthPixels, dm.heightPixels, Bitmap.Config.ARGB_8888);
m_canvas = new Canvas();
m_canvas.setBitmap(m_bitCanvas);
m_paint = new Paint();
m_canvas.drawBitmap(m_bitQQ, 0, 0, m_paint);
new Thread(this).start();
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(m_bitCanvas, 0, 0, m_paint);
}
public void run() {
while (!Thread.currentThread().isInterrupted())
{
try {
Thread.sleep(100);
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();
}
postInvalidate();
}
}
}