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

Android SurfaceView 运用实例

 2012-07-05 13:43:03 来源:WEB开发网   
核心提示: package gongzi.co.cc;import android.app.Activity;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.os.B

 package gongzi.co.cc;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
public class SurfaceActivity extends
Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final SurfaceView surfaceView = (SurfaceView)
findViewById(R.id.surfaceView1);
// surfaceView.setClickable(true);
surfaceView
.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(
View v) {
// TODO Auto-generated
method stub
// SurfaceView surfaceView
= (SurfaceView) v;
Canvas canvas =
surfaceView

.getHolder()

.lockCanvas();
Paint paint = new
Paint();
paint.setColor
(Color.BLUE);
paint.setAntiAlias
(true);
paint.setTextSize(24);
canvas.drawText(

"loveyou",
0, 100,
paint);
surfaceView

.getHolder()

.unlockCanvasAndPost(

canvas);
}
});
}
}

---------------2:主main
package gongzi.co.cc;
import android.app.Activity;
import android.os.Bundle;
public class SurfaceActivity extends
Activity {
@Override
protected void onCreate(
Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(new Click(this));
}
}
-----------SurfaceActivity.java
package gongzi.co.cc;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android

1 2 3 4  下一页

Tags:Android SurfaceView 运用

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