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

Android SurfaceView 运用实例

 2012-07-05 13:43:03 来源:WEB开发网   
核心提示:.graphics.Color;import android.graphics.Paint;import android.view.SurfaceHolder;import android.view.SurfaceView;public class Click extends SurfaceViewimplements
.graphics.Color;
import android.graphics.Paint;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class Click extends SurfaceView
implements
SurfaceHolder.Callback {
public Click(Context context) {
super(context);
// TODO Auto-generated constructor stub
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
Canvas canvas = holder
.lockCanvas();
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setAntiAlias(true);
paint.setTextSize(26);
canvas.drawText(
"love you gogogogogoigogoi",
100, 100, paint);
holder.unlockCanvasAndPost(canvas);
}
@Override
public void surfaceDestroyed(
SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}

------------图片和轨迹球
package gongzi.co.cc;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.SurfaceView;
public class Click extends SurfaceView {
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
}
@Override
public boolean onTouchEvent(
MotionEvent event) {
// TODO Auto-generated method stub
left = event.getX();
top = event.getY();
doDraw();
return super
.onTouchEvent(event);
}
@Override
public boolean onTrackballEvent(
MotionEvent event) {
// TODO Auto-generated method stub
left = event.getX();
top = event.getY();
doDraw();
return super
.onTrackballEvent(event);
}
private void doDraw() {
// TODO Auto-generated method stub
Canvas canvas = getHolder()
.lockCanvas();

上一页  1 2 3 4  下一页

Tags:Android SurfaceView 运用

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