标签:
1:首先来说横竖屏的问题
这里我是在onCreate方法中直接强制横屏竖屏的设置,
Button btn;
SurfaceView surfaceView;
//初始化布局
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
addListener();
}
//初始化
private void init() {
btn = (Button) findViewById(R.id.btn);//用来控制横竖屏的
surfaceView = (SurfaceView) findViewById(R.id.sv);
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setOrientation_Port();
} else {
setOrientation_Land();
}
}
//增加监听事件
private void addListener() {
btn.setOnClickListener(new BtnClick());
}
//监听事件的实施
class BtnClick implements OnClickListener {
@Override
public void onClick(View v) {
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setOrientation_Land();
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setOrientation_Port();
}
}
}
// 获取屏幕宽高
public void getwidth() {
WindowManager wm = this.getWindowManager();
width = wm.getDefaultDisplay().getWidth();
heigh = wm.getDefaultDisplay().getHeight();
}
// 竖屏设置
public void setOrientation_Port() {
getwidth();
int sv_width = width;
int sv_heigth = 2 * (heigh / 5);
RelativeLayout.LayoutParams cameraFL = new RelativeLayout.LayoutParams(
width, heigh);
cameraFL.setMargins(0, 0, 0, sv_heigth);
surfaceView.setLayoutParams(cameraFL);
}
//横屏设置
public void setOrientation_Land() {
getwidth();
RelativeLayout.LayoutParams cameraFL = new RelativeLayout.LayoutParams(
width, heigh);
cameraFL.setMargins(0, 0, 0, 0);
surfaceView.setLayoutParams(cameraFL);
}
这样就实现了通过点击按钮来实现横竖屏的切换。
2:自定义surfaceView的写法来实现动画的效果
Canvas(中文叫做”画布”)就和HTML5中的canvas标签一样可以在一定区域内自由绘制图形。Canvas+SurfaceView制作的动画与View Animation和Property Animation这类动画比起来更加适合大量的集中播放的动画,比如游戏画面、相机的图像显示等。
因为SurfaceView通常会在另一个专门的线程中不断重绘界面,所以不像其他动画那样要在主线程(UI线程)中播放动画的同时还要消耗一定的流畅度用来响应用户输入。
注意: canvas.rotate() .旋转是针对于x和y坐标的(0,0)点的,x和y轴是会旋转的,
还有一个旋转方法是canvas.rotate(90,x,y);就是绕x,y点旋转
package com.example.test1;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.res.AssetManager;
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.graphics.PorterDuff.Mode;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class GIFView extends SurfaceView implements SurfaceHolder.Callback,
Runnable {
// 上下文
@SuppressWarnings("unused")
private Context context;
// 线程运行标志
public static boolean flag = false;
// 画布
private Canvas canvas;
// holder对象
private SurfaceHolder holder;
// 画笔
private Paint paint;
// gif帧标志量
private int count = 0;
private Thread thread;
// 初始宽高
private int w = 0, h = 0;
// 方向
public static int oritation = 0;
// 刷新间隔
private static int delay_During = 300;
// 旋转角度
private static int rotate_r = 90;
private static int rotate_R = 180;
// 旋转矢量
private static int rotate_Left = 15;
private static int rotate_right = 60;
// 动画位置距离屏幕边界的量
private static int speed_w = 100;
private static int speed_h = 160;
private int width,height;
public GIFView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
this.context = context;
this.holder = this.getHolder();
holder.addCallback(this);
paint = new Paint();
paint.setColor(0xFFFFFFFF);
setFocusable(true);
// 设置背景透明
setZOrderOnTop(true);
holder.setFormat(PixelFormat.TRANSLUCENT);
}
//一旦surfaceView发生改变线程就启动不断的画,直到surfaceView销毁
@Override
public void run() {
// TODO Auto-generated method stub
while (flag) {
long start = System.currentTimeMillis();
drawView();
long end = System.currentTimeMillis();
try {
if (end - start < delay_During) {
Thread.sleep(delay_During - (end - start));
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
/**
* 从Assets中读取图 片
*/
private Bitmap getImageFromAssetsFile(String fileName) {
Bitmap image = null;
AssetManager am = getResources().getAssets();
try {
InputStream is = am.open(fileName);
image = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
// 画图 --利用矢量和角度来实现图片的方向的改变 ,由于四张图片组成一个向右的动画效果,所以需要通过旋转来实现8个不同的方向
private void drawView() {
// TODO Auto-generated method stub
try {
canvas = holder.lockCanvas();
if (canvas != null) {
// 设置透明
canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
paint.setColor(0xFFFFFFFF);
// 将整个画布移动
canvas.translate(50, 60);
switch (oritation) {
case 0: {
}
break;
case 1: {
canvas.save();
//canvas.rotate(90,x,y);就是绕x,y点旋转
canvas.rotate(rotate_R, 0, h / 2);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), 0 - rotate_right, h / 2 - rotate_Left,
paint);
canvas.restore();
}
break;
case 2: {
canvas.save();
canvas.rotate(-rotate_r, w / 2 - rotate_Left, rotate_right);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w / 2 - rotate_Left, rotate_right, paint);
canvas.restore();
}
break;
case 3: {
canvas.save();
canvas.rotate(0, w, h / 2);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - rotate_right, h / 2 - rotate_Left,
paint);
canvas.restore();
}
break;
case 4: {
canvas.save();
canvas.rotate(rotate_r, w / 2, h);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w / 2 - rotate_right, h - rotate_Left,
paint);
canvas.restore();
}
break;
case 5: {
canvas.save();
canvas.rotate(-135, 30, rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), -10, -10, paint);
canvas.restore();
}
break;
case 6: {
canvas.save();
canvas.rotate(-45, w - 30, rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - rotate_right, 10, paint);
canvas.restore();
}
break;
case 7: {
canvas.save();
canvas.rotate(45, w - rotate_right, h - rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - 70, h - rotate_right, paint);
canvas.restore();
}
break;
case 8: {
canvas.save();
canvas.rotate(135, 0, h);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), -70, h - rotate_Left, paint);
canvas.restore();
}
break;
count++;
if (count == 4) {
count = 0;
}
}
} catch (Exception e) {
} finally {
if (canvas != null) {
holder.unlockCanvasAndPost(canvas);
}
}
}
// Callback包含的方法
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
// 初始化并启动线程
w = this.getWidth() - speed_w;
h = this.getHeight() - speed_h;
flag = true;
thread = new Thread(this);
thread.start();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
// 停止线程
flag = false;
}
}
3:思想
底层是一个surfaceView处理触屏的事件,上面还有一层自定义的surfaceView设置为透明,底层的surfaceView向最上一层传递参数,来实现滑动不同的方向出发不同的动画效果
整体代码如下
xml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test1.MainActivity"
android:configChanges="keyboardHidden|orientation" >
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/btn" />
<ImageButton
android:id="@+id/imgBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:background="@drawable/cfg_ptz" />
<RelativeLayout
android:id="@+id/rl_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<SurfaceView
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/animation_list" />
<com.example.test1.GIFView
android:id="@+id/gif_View"
android:layout_width="wrap_content"
android:layout_height="300dp" />
</RelativeLayout>
</RelativeLayout>
底层的surfaceView代码
package com.example.test1;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
Button btn;
SurfaceView surfaceView;
RelativeLayout relativeLayout;
RelativeLayout relativeLayout2;
// surfaceView的大小设置
private int width;
private int heigh;
// 判断滑动的方向
private int x_down, y_down;
private int x_space, y_space;
// 方向的表示
public static final int TO_LEFT = 1;
public static final int TO_UP = 2;
public static final int TO_RIGHT = 3;
public static final int TO_DOWN = 4;
public static final int TO_LEFTUP = 5;
public static final int TO_RIGHTUP = 6;
public static final int TO_RIGHTDOWN = 7;
public static final int TO_LEFTDOWN = 8;
// 用于点击事件的效果
public static final int TO_CLICK = 9;
// 用于显示八个方向
public static final int TO_All = 10;
// 自定义view
private GIFView gif_View;
// 标志位
boolean flag;
public static final int parm = 1;
private static final OnClickListener ImgListener = null;
private ImageButton imageButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
addListener();
}
// 初始化
private void init() {
btn = (Button) findViewById(R.id.btn);
surfaceView = (SurfaceView) findViewById(R.id.sv);
relativeLayout = (RelativeLayout) findViewById(R.id.rl);
gif_View = (GIFView) findViewById(R.id.gif_View);
gif_View.setVisibility(View.VISIBLE);
relativeLayout2 = (RelativeLayout) findViewById(R.id.rl_small);
imageButton = (ImageButton) findViewById(R.id.imgBtn);
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setOrientation_Port();
gif_View.setVisibility(View.INVISIBLE);
} else {
setOrientation_Land();
gif_View.setVisibility(View.INVISIBLE);
}
btn.bringToFront();
imageButton.bringToFront();
}
// 点击事件
class BtnClick implements OnClickListener {
@Override
public void onClick(View v) {
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setOrientation_Land();
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setOrientation_Port();
}
}
}
// 竖屏设置
public void setOrientation_Port() {
getwidth();
int sv_width = width;
int sv_heigth = 2 * (heigh / 5);
RelativeLayout.LayoutParams cameraFL = new RelativeLayout.LayoutParams(
width, heigh);
cameraFL.setMargins(0, 0, 0, sv_heigth);
surfaceView.setLayoutParams(cameraFL);
}
// 获取屏幕宽高
public void getwidth() {
WindowManager wm = this.getWindowManager();
width = wm.getDefaultDisplay().getWidth();
heigh = wm.getDefaultDisplay().getHeight();
}
// 横屏设置
public void setOrientation_Land() {
getwidth();
RelativeLayout.LayoutParams cameraFL = new RelativeLayout.LayoutParams(
width, heigh);
cameraFL.setMargins(0, 0, 0, 0);
surfaceView.setLayoutParams(cameraFL);
}
private void addListener() {
btn.setOnClickListener(new BtnClick());
surfaceView.setOnTouchListener(new onTouch());
imageButton.setOnClickListener(new ImgListener());
}
private class ImgListener implements OnClickListener {
@Override
public void onClick(View v) {
gif_View.oritation = TO_All;
Log.e("TAG", "-----------------tupian");
gif_View.setVisibility(View.VISIBLE);
}
}
// 触屏事件的实施
private class onTouch implements OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x_down = (int) event.getX();
y_down = (int) event.getY();
flag = true;
Log.i("TAG--ACTION_DOWN", x_down + "-------------------"
+ y_down);
gif_View.oritation = TO_CLICK;
gif_View.setVisibility(View.VISIBLE);
break;
case MotionEvent.ACTION_MOVE:
if (flag) {
int x = (int) event.getX();
int y = (int) event.getY();
Log.i("TAG--ACTION_MOVE", x + "-------------------" + y);
x_space = (int) (event.getX() - x_down);
y_space = (int) (event.getY() - y_down);
Log.i("TAG--ACTION_UP", x_space + "-------------------"
+ y_space);
if (Math.abs(x_space) < 50 | Math.abs(y_space) < 50) {
gif_View.oritation = TO_CLICK;
gif_View.setVisibility(View.VISIBLE);
}
if (Math.abs(x_space) > 100 | Math.abs(y_space) > 100) {
// 确定不是点击事件
if (y_space < 0 & x_space > -30 & x_space < 30) {
// 向上
// 向上
flag = false;
Log.i("TAG", "向上");
gif_View.oritation = TO_UP;
gif_View.setVisibility(View.VISIBLE);
}
if (y_space < -35 & x_space > 50) {
// 向右上
flag = false;
Log.e("TAG", " 右上");
gif_View.oritation = TO_RIGHTUP;
gif_View.setVisibility(View.VISIBLE);
}
if (y_space < -35 & x_space < -50) {
// 左上
flag = false;
Log.e("TAG", "左上");
gif_View.oritation = TO_LEFTUP;
gif_View.setVisibility(View.VISIBLE);
}
// -------------------------------------
if (y_space > 0 & x_space < 30 & x_space > -30) {
// 向下
flag = false;
Log.e("TAG", " 向下");
gif_View.oritation = TO_DOWN;
gif_View.setVisibility(View.VISIBLE);
}
if (y_space > 35 & x_space < -35) {
// 左下
flag = false;
Log.e("TAG", "左下");
gif_View.oritation = TO_LEFTDOWN;
gif_View.setVisibility(View.VISIBLE);
}
if (y_space > 35 & x_space > 35) {
// 右下
flag = false;
Log.e("TAG", "右下");
gif_View.oritation = TO_RIGHTDOWN;
gif_View.setVisibility(View.VISIBLE);
}
if (x_space < 0 & -30 < y_space & y_space < 30) {
// 向左
flag = false;
Log.e("TAG", "向左");
gif_View.oritation = TO_LEFT;
gif_View.setVisibility(View.VISIBLE);
}
if (x_space > 0 & -30 < y_space & y_space < 30) {
// 向右
flag = false;
Log.e("TAG", "向右");
gif_View.oritation = TO_RIGHT;
gif_View.setVisibility(View.VISIBLE);
}
}
}
break;
case MotionEvent.ACTION_UP:
gif_View.setVisibility(View.INVISIBLE);
break;
default:
break;
}
return true;
}
}
}
透明的surfaceView代码
package com.example.test1;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.res.AssetManager;
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.graphics.PorterDuff.Mode;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class GIFView extends SurfaceView implements SurfaceHolder.Callback,
Runnable {
// 上下文
@SuppressWarnings("unused")
private Context context;
// 线程运行标志
public static boolean flag = false;
// 画布
private Canvas canvas;
// holder对象
private SurfaceHolder holder;
// 画笔
private Paint paint;
// gif帧标志量
private int count = 0;
private Thread thread;
// 初始宽高
private int w = 0, h = 0;
// 方向
public static int oritation = 0;
// 刷新间隔
private static int delay_During = 300;
// 旋转角度
private static int rotate_r = 90;
private static int rotate_R = 180;
// 旋转矢量
private static int rotate_Left = 15;
private static int rotate_right = 60;
// 动画位置距离屏幕边界的量
private static int speed_w = 100;
private static int speed_h = 160;
private int width,height;
public GIFView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
this.context = context;
this.holder = this.getHolder();
holder.addCallback(this);
paint = new Paint();
paint.setColor(0xFFFFFFFF);
setFocusable(true);
// 设置背景透明
setZOrderOnTop(true);
holder.setFormat(PixelFormat.TRANSLUCENT);
}
@Override
public void run() {
// TODO Auto-generated method stub
while (flag) {
long start = System.currentTimeMillis();
drawView();
long end = System.currentTimeMillis();
try {
if (end - start < delay_During) {
Thread.sleep(delay_During - (end - start));
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
/**
* 从Assets中读取图 片
*/
private Bitmap getImageFromAssetsFile(String fileName) {
Bitmap image = null;
AssetManager am = getResources().getAssets();
try {
InputStream is = am.open(fileName);
image = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
// 画图 --利用矢量和角度来实现图片的方向的改变
private void drawView() {
// TODO Auto-generated method stub
try {
canvas = holder.lockCanvas();
if (canvas != null) {
// 设置透明
canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
paint.setColor(0xFFFFFFFF);
// 将整个画布移动
canvas.translate(50, 60);
switch (oritation) {
case 0: {
}
break;
case 1: {
//向左
canvas.save();
canvas.rotate(rotate_R, 0, h / 2);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), 0 - rotate_right, h / 2 - rotate_Left,
paint);
canvas.restore();
}
break;
case 2: {
canvas.save();
canvas.rotate(-rotate_r, w / 2 - rotate_Left, rotate_right);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w / 2 - rotate_Left, rotate_right, paint);
canvas.restore();
}
break;
case 3: {
canvas.save();
canvas.rotate(0, w, h / 2);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - rotate_right, h / 2 - rotate_Left,
paint);
Log.e("TAG", "--------------------333333");
canvas.restore();
}
break;
case 4: {
canvas.save();
canvas.rotate(rotate_r, w / 2, h);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w / 2 - rotate_right, h - rotate_Left,
paint);
canvas.restore();
}
break;
case 5: {
canvas.save();
canvas.rotate(-135, 30, rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), -10, -10, paint);
canvas.restore();
}
break;
case 6: {
canvas.save();
canvas.rotate(-45, w - 30, rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - rotate_right, 10, paint);
canvas.restore();
}
break;
case 7: {
canvas.save();
canvas.rotate(45, w - rotate_right, h - rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - 70, h - rotate_right, paint);
canvas.restore();
}
break;
case 8: {
canvas.save();
canvas.rotate(135, 0, h);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), -70, h - rotate_Left, paint);
canvas.restore();
}
break;
case 9: {
Log.e("TAG","---------------9999999999-----------------");
canvas.save();
canvas.drawBitmap(getImageFromAssetsFile("b" + count
+ ".png"), 200,300, paint);
Log.e("TAG","---------------9999999999");
canvas.restore();
}
break;
case 10: {
Log.e("TAG","---------------10-----------------");
canvas.save();
canvas.rotate(rotate_R, 0, h / 2);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), 0 - rotate_right, h / 2 - rotate_Left,
paint);
canvas.restore();
canvas.save();
canvas.rotate(-rotate_r, w / 2 - rotate_Left, rotate_right);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w / 2 - rotate_Left, rotate_right, paint);
canvas.restore();
canvas.save();
canvas.rotate(0, w, h / 2);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - rotate_right, h / 2 - rotate_Left,
paint);
Log.e("TAG", "--------------------333333");
canvas.restore();
canvas.save();
canvas.rotate(rotate_r, w / 2, h);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w / 2 - rotate_right, h - rotate_Left,
paint);
canvas.restore();
canvas.save();
canvas.rotate(-135, 30, rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), -10, -10, paint);
canvas.restore();
canvas.save();
canvas.rotate(-45, w - 30, rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - rotate_right, 10, paint);
canvas.restore();
canvas.save();
canvas.rotate(45, w - rotate_right, h - rotate_Left);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), w - 70, h - rotate_right, paint);
canvas.restore();
canvas.save();
canvas.rotate(135, 0, h);
canvas.drawBitmap(getImageFromAssetsFile("a" + count
+ ".png"), -70, h - rotate_Left, paint);
canvas.restore();
}
break;
}
count++;
if (count == 4) {
count = 0;
}
}
} catch (Exception e) {
} finally {
if (canvas != null) {
holder.unlockCanvasAndPost(canvas);
}
}
}
// Callback包含的方法
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
// 初始化并启动线程
w = this.getWidth() - speed_w;
h = this.getHeight() - speed_h;
flag = true;
thread = new Thread(this);
thread.start();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
// 停止线程
flag = false;
}
}
小弟也是刚刚接触android的具体项目 :上述如果有不对的地方欢迎留言,修改!
android实现横竖屏8个方向触屏事件的捕捉并有相对应的动画提示
标签:
原文地址:http://blog.csdn.net/qdh186/article/details/51932689