WEB开发网
开发学院手机开发Android 开发 Android SurfaceView 运用实例 阅读

Android SurfaceView 运用实例

 2012-07-05 13:43:03 来源:WEB开发网   
核心提示:canvas.drawBitmap(mBitmap,left, top, null);getHolder().unlockCanvasAndPost(canvas);}}---半透明 桌面package gongzi.co.cc;import android.app.Activity;import android.co
canvas.drawBitmap(mBitmap,
left, top, null);
getHolder()
.unlockCanvasAndPost(
canvas);
}
}
-------------------半透明 桌面
package gongzi.co.cc;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class Click extends SurfaceView
implements
SurfaceHolder.Callback {
float left;
float top;
Bitmap mBitmap = BitmapFactory
.decodeResource(
getContext()
.getResources
(),
R.drawable.ic_launcher);
public Click(Context context) {
super(context);
// TODO Auto-generated constructor stub
getHolder()
.setFormat(

PixelFormat.TRANSLUCENT);
getHolder().addCallback(this);
}
@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
doDraw();
}
@Override
public void surfaceDestroyed(
SurfaceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public boolean onTouchEvent(
MotionEvent event) {
// TODO Auto-generated method stub
left = event.getX();
top = event.getY();
doDraw();
return super
.onTouchEvent(event);
}
void doDraw() {
// TODO Auto-generated method stub
Canvas canvas = getHolder()
.lockCanvas();
canvas.drawBitmap(mBitmap,
left, top, null);
getHolder()
.unlockCanvasAndPost(
canvas);
}
}
---------manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android

上一页  1 2 3 4  下一页

Tags:Android SurfaceView 运用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接