很简单的实现,作为软件专业大二在校生,接触安卓还没两个月,没事写着玩练练手,请大神们莫要嘲讽
重力小球主要参考了http://www.xuanyusong.com/archives/337这篇文章,我写出来的代码风格都完全一样,惭愧惭愧
(我的第一篇CSDN博客,值得纪念一手,蛤蛤蛤
package com.example.a29205.myapp10;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
final static String TAG="MainActivity";
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 全屏显示窗口
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//强制横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// 显示自定义的游戏View
mysuferView mysuferView=new mysuferView(this);
setContentView(mysuferView);
}
@Override
protected void onPause() {
super.onPause();
}
}
然后就是自定义的suferView
package com.example.a29205.myapp10;
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.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.u