編輯:關於Android編程
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.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();
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="http://schemas.android.com/apk/res/android"
package="gongzi.co.cc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".SurfaceActivity"
android:theme="@android:style/Theme.Translucent"
>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
作者:gongzibaiProgressDialog的基本用法ProgressDialog為進度對話框。android手機自帶的對話框顯得比較單一,我們可以通過ProgressDialog來自己
AnimationListener聽名字就知道是對Animation設置監聽器,說簡單點就是在Animation動畫效果開始執行前,執行完畢和重復執行時可以觸發監聽器,從
本文實例講述了Android基於API的Tabs3實現仿優酷tabhost效果。分享給大家供大家參考,具體如下:前兩天老師就讓自己寫個視頻播放器客戶端,這個是他上課講的一
手機中保存並記錄著很多我們個人數據,比如浏覽器記錄、微信賬號、聊天記錄等,這些信息如果被有心人盯上自然後後患無窮。有時候我們會將手機借給好友,或是購新機後在