android 自定义view关闭硬件加速之后对于连续按键按下的操作反应好像很迟钝,这是为什么?

今天早上在技术问答里看到一个自定义view,在这个自定义view里边就是调用了canvas.drawBitmap()方法,他用响应按键按下的方法来改变bitmap的绘制位置。我记得以前查过资料,在一些自定义view的一些操作中是不支持硬件加速的。所以我试着去把硬件加速关闭,但是情况来了,程序对按键按下的响应很迟钝,爆出这样的异常:Dropped event because it is stale.有些不明白,即便是关闭了硬件加速也不至于这么迟钝吧?求大神赐教。
这是那个技术问答的链接:http://ask.csdn.net/questions/263461

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
android 自定义键盘报错

android.inputmethodservice.KeyboardView用这个自定义键盘,有时回出现如下错误,求解: ava.lang.RuntimeException: InputChannel is not initialized. at android.view.InputEventReceiver.nativeInit(Native Method) at android.view.InputEventReceiver.(InputEventReceiver.java:70) at android.view.ViewRootImpl$WindowInputEventReceiver.(ViewRootImpl.java:5646) at android.view.ViewRootImpl.setView(ViewRootImpl.java:609) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2844) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2244) at android.app.ActivityThread.access$800(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5047) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) at dalvik.system.NativeStart.main(Native Method)

Android自定义Button的OnKeyDown方法没反应

代码如下: 自定义Button类 public class MyButton extends Button{ public MyButton(Context context,AttributeSet set) { super(context,set); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { super.onKeyDown(keyCode,event); TextView tv = (TextView) findViewById(R.id.aa); tv.setText("123232323"); Log.v("111","2222"); return super.onKeyDown(keyCode, event); } } 界面xml代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:orientation="vertical" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:id="@+id/aa" android:layout_width="match_parent" android:layout_height="wrap_content" /> <com.example.cg.view.MyButton android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>

android 自定义键盘问题

我想做个自定义键盘,做出来后 出现了个BUG, 我们一般点击键盘某个字母会出现个小框框 然后显示这个字母 我做出来的时候显示是透明的 求解如何设置这个属性颜色

Android Studio自定义布局中的Button不响应点击事件

最近开始跟着郭霖大神的《第一行代码》学习Android开发,遇到一个问题 自定义布局之后,模拟器运行时Button不响应单击事件 代码如下 MainActivity.java package com.example.uilayouttest; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActionBar actionBar = getSupportActionBar(); if (actionBar != null){ actionBar.hide(); } } } activity_main.xml文件 <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <!--android:orientation="horizontal"--> <include layout="@layout/title"/> <com.example.uilayouttest.TitleLayout android:layout_width="match_parent" android:layout_height="wrap_content"> </com.example.uilayouttest.TitleLayout> </LinearLayout> title.xml文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="65dp" android:background="@drawable/back_bg" > <Button android:id="@+id/title_back" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="top" android:layout_margin="5dp" android:text="Back" android:textColor="#fff"/> <TextView android:id="@+id/title_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_weight="1" android:gravity="center" android:text="Title Text" android:textColor="#fff" android:textSize="28sp"/> <Button android:id="@+id/title_edit" android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="top" android:layout_margin="5dp" android:background="@drawable/edit" android:text="" /> </LinearLayout> TitleLayout.java类 package com.example.uilayouttest; import android.app.Activity; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; import android.widget.Toast; public class TitleLayout extends LinearLayout { public TitleLayout(Context context, AttributeSet attrs){ super(context,attrs); LayoutInflater.from(context).inflate(R.layout.title, this); Button titleBack = (Button) findViewById(R.id.title_back); Button titleEdit = (Button) findViewById(R.id.title_edit); titleBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Activity) getContext()).finish(); Log.d("data", "onClick:到底有没有点击我 "); Toast.makeText(getContext(), "你点击了Back按钮", Toast.LENGTH_SHORT).show(); } }); titleEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), "你点击了Edit按钮", Toast.LENGTH_SHORT).show(); } }); } } ``` ```

toolbar自定义返回图标怎么控制drawerlayout

度娘了一下发现知道了怎么弹出的方法,但是怎么再次点击图标把drawerlayout给隐藏?? ``` toolbar.setNavigationIcon(R.mipmap.ic_launcher); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawlayout.openDrawer(GravityCompat.START); } }); ``` 上面的代码能使drawerlayout弹出来,但是怎么再次点击把drawerlayout弹回去

android notifacation添加按键并响应按键事件

想在notification中添加几个控制音乐播放的next/prev/play/stop的按键,在网上查了好多方法,可是都没有解决,按键是在notification上面显示出来了,可是点击那些按键都没有响应。应该要怎么把按键和事件响应联系起来啊?

android按钮的渐变颜色效果

我在xml中的代码如下: <item > <shape> <gradient android:startColor= "#AE845c" android:endColor="#935Fc0" /> </shape> </item> 希望出现这样的效果: ![CSDN移动问答][1] 不知道怎么实现? [1]: http://i.stack.imgur.com/y4ccZ.png

Android 悬浮窗获取点击拖拽事件

之前参照网上例子写过一个demo,实现在Activity中点击最小化按钮,将该Activity finish,并启动servie生成一个悬浮按钮,可点击也可拖拽; 最近工作需要也做一个相似的悬浮窗,悬浮按钮生成了,App被Home也能存在,不会 消失,但该悬浮按钮却没法捕获点击和拖拽事件。 这两个代码几乎一摸一样,请大神们帮忙看下是哪里出的问题,谢谢! 代码如下: package com.example.menqi.myapplication; import android.app.Service; import android.content.Context; import android.content.Intent; import android.graphics.PixelFormat; import android.os.IBinder; import android.util.DisplayMetrics; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; public class MyService extends Service { private WindowManager mWindowManager; private WindowManager.LayoutParams mLayoutParams; /** * float的布局view */ private View mFloatView; private ViewGroup glSurfaceView; private int mFloatWinWidth,mFloatWinHeight;//悬浮窗的宽高 //private int mFloatWinMarginTop,mFloatWinMarginRight; public MyService() { } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. return null; } @Override public void onCreate() { super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { createWindowManager(); createFloatView(); return super.onStartCommand(intent, flags, startId); } @Override public void onDestroy() { super.onDestroy(); removeFloatView(); } private void createWindowManager() { // 取得系统窗体 mWindowManager= (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); //计算得出悬浮窗口的宽高 DisplayMetrics metric =new DisplayMetrics(); mWindowManager.getDefaultDisplay().getMetrics(metric); int screenWidth = metric.widthPixels; mFloatWinWidth = screenWidth *1/3; mFloatWinHeight=mFloatWinWidth*4/3; //mFloatWinMarginTop= (int)this.getResources().getDimension(R.dimen.rkcloud_av_floatwin_margintop); //mFloatWinMarginRight= (int)this.getResources().getDimension(R.dimen.rkcloud_av_floatwin_marginright); // 窗体的布局样式 // 获取LayoutParams对象 mLayoutParams=new WindowManager.LayoutParams(); // 确定爱悬浮窗类型,表示在所有应用程序之上,但在状态栏之下 //TODO? 在android2.3以上可以使用TYPE_TOAST规避权限问题 mLayoutParams.type= WindowManager.LayoutParams.TYPE_TOAST;//TYPE_PHONE mLayoutParams.format= PixelFormat.RGBA_8888; mLayoutParams.flags= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; // 悬浮窗的对齐方式 mLayoutParams.gravity= Gravity.LEFT| Gravity.TOP; // 悬浮窗的位置 mLayoutParams.x=70; mLayoutParams.y=210; mLayoutParams.width=mFloatWinWidth; mLayoutParams.height=mFloatWinHeight; } //开始触控的坐标,移动时的坐标(相对于屏幕左上角的坐标) private int mTouchStartX, mTouchStartY, mTouchCurrentX, mTouchCurrentY; //开始时的坐标和结束时的坐标(相对于自身控件的坐标) private int mStartX, mStartY, mStopX, mStopY; //判断悬浮窗口是否移动,这里做个标记,防止移动后松手触发了点击事件 private boolean isMove; /** * 创建悬浮窗 */ private void createFloatView() { LayoutInflater inflater = LayoutInflater.from(getApplicationContext()); mFloatView= inflater.inflate(R.layout.floatlayout, null); glSurfaceView= (ViewGroup)mFloatView.findViewById(R.id.VOIPFloatView); //glSurfaceView.setPreserveEGLContextOnPause(true); glSurfaceView.setKeepScreenOn(true); mWindowManager.addView(mFloatView,mLayoutParams); mFloatView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v,MotionEvent event) { int action = event.getAction(); /*if(MotionEvent.ACTION_DOWN == action) { mStartX=mLastX= (int) event.getRawX(); mStartY=mLastY= (int) event.getRawY(); }else if(MotionEvent.ACTION_UP == action) { int dx = (int) event.getRawX() -mStartX; int dy = (int) event.getRawY() -mStartY; if(Math.abs(dx) >5|| Math.abs(dy) >5) { return true; } }else if(MotionEvent.ACTION_MOVE == action) { int dx = (int) event.getRawX() -mLastX; int dy = (int) event.getRawY() -mLastY; mLayoutParams.x=mLayoutParams.x- dx; mLayoutParams.y=mLayoutParams.y+ dy; mWindowManager.updateViewLayout(mFloatView,mLayoutParams); mLastX= (int) event.getRawX(); mLastY= (int) event.getRawY(); } return false;*/ switch (action) { case MotionEvent.ACTION_DOWN: isMove = false; mTouchStartX = (int) event.getRawX(); mTouchStartY = (int) event.getRawY(); mStartX = (int) event.getX(); mStartY = (int) event.getY(); break; case MotionEvent.ACTION_MOVE: mTouchCurrentX = (int) event.getRawX(); mTouchCurrentY = (int) event.getRawY(); mLayoutParams.x += mTouchCurrentX - mTouchStartX; mLayoutParams.y += mTouchCurrentY - mTouchStartY; mWindowManager.updateViewLayout(mFloatView, mLayoutParams); mTouchStartX = mTouchCurrentX; mTouchStartY = mTouchCurrentY; break; case MotionEvent.ACTION_UP: mStopX = (int) event.getX(); mStopY = (int) event.getY(); if (Math.abs(mStartX - mStopX) >= 1 || Math.abs(mStartY - mStopY) >= 1) { isMove = true; } break; } //如果是移动事件不触发OnClick事件,防止移动的时候一放手形成点击事件 return isMove; } }); mFloatView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ToVOIPActivity(); MyService.this.stopSelf(); } }); /*VideoRendererGui.setView(glSurfaceView, new Runnable() { @Override public void run() { if(WebRtcHelperEx.getInstance().isWebRtcChanelAlive()) { WebRtcHelperEx.getInstance().updateVideoUI(WebRtcHelperEx.latestLocalVideoSize,WebRtcHelperEx.latestRemoteVideoSize); } } }); if(WebRtcHelperEx.getInstance().isWebRtcChanelAlive()) { LogEx.d(TAG,"createFloatView: webrtc instance is alive and we will call resetRenders"); WebRtcHelperEx.getInstance().resetRenders(); WebRtcHelperEx.getInstance().updateVideoUI(WebRtcHelperEx.VIDEOSIZE_SMALL,WebRtcHelperEx.VIDEOSIZE_BIG); }*/ } private void removeFloatView() { if(mFloatView != null && mWindowManager != null) { mWindowManager.removeView(mFloatView); } } /** * 单击后回到@WebRTCActivity以切换为大尺寸页面 */ private void ToVOIPActivity() { //TODO跳转到Activity Intent intentToActivity = new Intent(this, Main2Activity.class);//WebPhoneIncomingCallActivity来电页面 intentToActivity.setFlags(FLAG_ACTIVITY_NEW_TASK); startActivity(intentToActivity); } } layout <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/VOIPFloatView" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageButton android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/avcallfloat" android:scaleType="centerInside" /> </FrameLayout> </RelativeLayout> </RelativeLayout>

Android点击按钮后弹窗设置时间

![图片说明](https://img-ask.csdn.net/upload/201810/07/1538899042_996404.jpg) ![图片说明](https://img-ask.csdn.net/upload/201810/07/1538899065_607276.jpg) 弹窗显示这个时间选择器

如何android 在view里面放button或textview 自动换行并能居中

[打开手机布局,类似这样的效果](https://img-ask.csdn.net/upload/201604/03/1459675400_859059.png) 网上找的大多都是继承的viewGroup的自定义控件,但不能居中诶

andorid 如何让自定义的坐标驱动各种点击事件、手势等。

1.各种手势,触摸,键盘鼠标事件android都有能有很好的支持。都是系统自己监控判断view上的坐标。 2.能不能用自己给的坐标作为事件的驱动条件呢(例如要用传感器获得的坐标)?比如给我坐标100.100然后系统把其认为是触摸点坐标,然后按部就班完成触摸式事件,有没有这样的函数? 我自己目前的做法是自定义view去一个个画按钮,一个个去自己写事件,及其麻烦且缺乏通用性。

Android如何让父控件拦截子控件的长按事件?没金币了~~~

现在有个需求是,一个父控件里边有几个子控件,每个子控件可以响应自己的单击事件,但是如果是长按父控件的区域就响应长按事件,现在的问题是如何让子控件不处理长按事件交给父控件处理呢?

所做Android打砖块代码其中 出错 求教

下面是代码 可其中出现了一个错误(做了标记),不知道怎么解决,可否有高手帮我看看,能不能稍作修改一下,做成正确的。 就是这句错了 myview = new BallView(this); package sen.tan; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; public class dazhuankuaiActivity extends Activity { BallView myview; public static int screenWidth ; public static int screenHeight; private TextView textview; Button kaishi,jieshu,guanyu; ImageView image; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String string = "欢迎进入疯狂打砖块游戏"; image = (ImageView) this.findViewById(R.id.image); image.setImageResource(R.drawable.img1); textview =(TextView) this.findViewById(R.id.textview); textview.setTextSize(20); textview.setTextColor(Color.GREEN); textview.setBackgroundColor(Color.RED); textview.setText(string); kaishi=(Button)findViewById(R.id.button1); guanyu=(Button)findViewById(R.id.button2); jieshu=(Button)findViewById(R.id.button3); kaishi.setWidth(250); guanyu.setWidth(200); jieshu.setWidth(150); kaishi.setTextSize(35); guanyu.setTextSize(29); jieshu.setTextSize(24); jieshu.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v) { dazhuankuaiActivity.this.finish(); } }); guanyu.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ textview.setText("本游戏由xxx制作,此游戏控制左右按键,来回移动挡板,不让小球掉落,当小球把上方砖块全部打完时,游戏胜利"); } }); kaishi.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels; screenHeight = dm.heightPixels; setTitle("宽"+screenWidth+" 高"+screenHeight); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); `myview = new BallView(this);` //错误在这里 setContentView(myview); } public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_MENU: myview.resetGame(); break; case KeyEvent.KEYCODE_DPAD_CENTER: myview.ball_isRun = !myview.ball_isRun; break; case KeyEvent.KEYCODE_DPAD_LEFT: if(myview.ball_isRun){ if(myview.board_left<=myview.board_x_move) { myview.board_left=0; myview.board_right=myview.board_length; }else{ myview.board_left-=myview.board_x_move; myview.board_right-=myview.board_x_move;} } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if(myview.ball_isRun){ if(screenWidth-myview.board_right<=myview.board_x_move ) { myview.board_left=screenWidth-myview.board_length; myview.board_right=screenWidth; }else{ myview.board_left+=myview.board_x_move; myview.board_right+=myview.board_x_move; } } break; case KeyEvent.KEYCODE_DPAD_UP: if(myview.ball_isRun){ if( myview.board_alterable_top==myview.board_default_top) { myview.board_alterable_top-=myview.boardYadd; myview.board_alterable_bottom-=myview.boardYadd; } } break; case KeyEvent.KEYCODE_DPAD_DOWN: if(myview.ball_isRun){ if( myview.board_alterable_top==myview.board_default_top-myview.boardYadd ) { myview.board_alterable_top=myview.board_default_top; myview.board_alterable_bottom=myview.board_alterable_top+myview.board_thickness; } } break; case KeyEvent.KEYCODE_BACK: dazhuankuaiActivity.this.finish(); break; }//end switch return false; } //按键弹起事件 } ); } } package sen.tan; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RadialGradient; import android.graphics.Shader; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; public class BallView extends SurfaceView implements SurfaceHolder.Callback, Runnable { //线程延时控制 final int ball_sleep=1;//毫秒,延时越大,球速越慢 final int ball_r= 8;//小球半径 final float ball2_r= 8;//底下滚珠小球半径 final int ballXorYadd = 4;//小球的基本位移。测试可行值:2,4 //获取屏幕宽度和高度 int screen_width;//320; int screen_height;//480; //砖的属性 int brick_width;//每块砖宽 int brick_height;//每块砖高 boolean brick_exist[];//砖是否存在 int k ;// 列//到for循环里才初始化 int j ;// 行 int brick_left = brick_width*(k-1);//到判断语句才初始化 int brick_right = brick_width*k; int brick_top = brick_height*j; int brick_bottom = brick_height*(j+1); //挡板的属性 int board_length;//挡板长度:80比较合适,可以随意修改,但别超过screen_width final int boardYadd = 16;//按上下键时挡板y方向位移量。经验证4、8、16可以,12不行 final int board_x_move = 30;//挡板x方向位移量:可以随意自定义 int board_left;//挡板左侧(可变) int board_right;//挡板右侧(可变) int board_thickness;//挡板厚度 int board_default_top;//即435,挡板的top面初始位置 int board_alterable_top;//挡板上侧(可变) int board_alterable_bottom;//挡板下侧(可变) int ball_default_x;//球的初始x坐标 int ball_default_y;//球的初始y坐标 //球的即时坐标(可变): int ball_x;//球心横坐标 int ball_y;//球心纵坐标 //球的前一步的y坐标 int ball_previous_y; int ball_x_speed;//球的横向偏移量//可变 int ball_y_speed;//球的纵向偏移量//可变 boolean ball_isRun;//球是否在动 // 控制循环 boolean mbLoop; // 定义SurfaceHolder对象 SurfaceHolder mSurfaceHolder = null; //获得分数 int score; /* 唤醒渐变渲染 */ Shader mRadialGradient = null; //------------------------------------------------------------------------------------------------------// public BallView(Context context) { super(context); // 实例化SurfaceHolder mSurfaceHolder = this.getHolder(); // 添加回调 mSurfaceHolder.addCallback(this); this.setFocusable(true); //获取屏幕宽度和高度 screen_width = dazhuankuaiActivity.screenWidth;//320 screen_height = dazhuankuaiActivity.screenHeight;//480 //砖的属性 brick_width = screen_width/5;//每块砖宽64 brick_height = screen_height/15;//每块砖高32 //挡板的属性 board_length = screen_width/4;//挡板长度:80比较合适,可以随意修改,但别超过screen_width board_left = (screen_width-board_length)/2;//挡板左侧(可变) board_right = (screen_width+board_length)/2;//挡板右侧(可变) board_thickness = 5;//挡板厚度 board_default_top = 13*screen_height/15;//即435,挡板的top面初始位置 board_alterable_top = board_default_top;//挡板上侧(可变) board_alterable_bottom = board_alterable_top+board_thickness;//挡板下侧(可变) ball_default_x = screen_width/2;//球的初始x坐标 ball_default_y = board_default_top - ball_r;//球的初始y坐标 //球的即时坐标(可变): ball_x = ball_default_x; ball_y = ball_default_y; //球的前一步的y坐标 ball_previous_y = 0; ball_x_speed = ballXorYadd;//球的横向偏移量 ball_y_speed = ballXorYadd;//球的纵向偏移量 mbLoop = true; ball_isRun = false; score=0; brick_exist = new boolean[25]; for (int i = 0; i < 25; i++) { brick_exist[i] = true; } /* 构建RadialGradient对象,设置半径的属性 */ mRadialGradient = new RadialGradient(ball_x, ball_y, ball_r,//球中心坐标x,y,半径r new int[]{Color.WHITE,Color.BLUE,Color.GREEN,Color.RED,Color.YELLOW},//颜色数组 null,//颜色数组中每一种颜色对应的相对位置,为空的话就是平均分布,由中心向外排布 Shader.TileMode.REPEAT);//渲染模式:重复 } public void resetGame(){ ball_isRun = false; score =0;//分数 ball_x_speed = ballXorYadd;//球的横向偏移量 ball_y_speed = ballXorYadd;//球的纵向偏移量 ball_x = screen_width/2;//球心起始横坐标 ball_y = board_default_top - ball_r;//球心起始纵坐标 board_left = (screen_width-board_length)/2;//挡板左侧 board_right = (screen_width+board_length)/2;//挡板右侧 board_alterable_top = board_default_top;//挡板上侧 board_alterable_bottom = board_alterable_top+board_thickness;//挡板下侧 for (int i = 0; i < 25; i++) { brick_exist[i] = true; } } //---------------------------------绘图循环开始---------------------------------- public void run() { while (mbLoop&&!Thread.currentThread().isInterrupted()) { try { Thread.sleep(ball_sleep); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } //球的前一步y坐标 ball_previous_y = ball_y; if (ball_isRun) { ballRunning();// 让小球移动 boardPositionCheck();//检测挡板是否处于“中线”位置,是就随小球上升一步,直至到“上线” hitWallCheck();//墙壁碰撞检测 hitBoardCheck();//挡板碰撞检测 hitBrickCheck();//砖块碰撞检测 } synchronized (mSurfaceHolder) { Draw(); } } } //---------------------------------绘图循环结束---------------------------------- //------------------------------------------------------------------------------ //让小球移动 public void ballRunning() { ball_x += ball_x_speed; ball_y -= ball_y_speed; } //朝左或朝右碰撞后小球水平方向逆向 public void ballLeftOrRightHit() { ball_x_speed *= -1; } //朝上或朝下碰撞后小球竖直方向逆向 public void ballUpOrDownHit() { ball_y_speed *= -1; } public void ballcornerHit() { ball_x_speed *= -1; ball_y_speed *= -1; } public void ballStraightUp() {//功能没实现,这是多余代码 ball_x_speed = 0;//注意在其他地方恢复 ball_y_speed *= -1; } //-------------------墙壁碰撞检测开始------------------------------------- public void hitWallCheck() { // 左碰墙 if (ball_x <= ball_r && ball_y >= ball_r && ball_y <= screen_height) { ballLeftOrRightHit(); // 右碰墙 } if (ball_x >= screen_width - ball_r && //不能写为 else if,因为可能恰好碰到角落。 ball_y >= ball_r && ball_y <= screen_height) { ballLeftOrRightHit(); } // 上碰墙 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && ball_y <= ball_r + brick_height) //、、、、、、、、、、、、、、、25号修改 { ballUpOrDownHit(); } // 下碰墙 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && ball_y >= screen_height-ball_r) { ballUpOrDownHit(); if(score<=10){ score = 0; } else score-=10; } } //-------------------墙壁碰撞检测结束------------------------------------- //-----------------------------挡板碰撞检测开始--------------------------- public void hitBoardCheck() { // 下碰挡板正面 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && //在屏幕内,起码条件 ball_x >= board_left && ball_x <= board_right && //在挡板X域上方 ball_y == board_alterable_top - ball_r &&//球面与挡板相切 ball_previous_y <= board_alterable_top - ball_r //确定球是从上方下落 ) { if(board_alterable_top==board_default_top-boardYadd ){//如果弹簧伸张,挡板位于上线 ballHitBoardlower();//作用:ball_y_move减小;挡板被打下;小球Y向运动反向 } else if(board_alterable_top==board_default_top){//如果弹簧压缩,挡板位于下线 boardHitBallHigher();//作用:ball_y_move增加;挡板弹上;小球Y向运动反向 } } //斜碰挡板右上角//经验证有效 else if(Math.pow(board_right-ball_x, 2)+Math.pow(board_alterable_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>board_right && ball_y<board_alterable_top) { ballcornerHit(); } //斜碰挡板的左上角//经验证有效 else if(Math.pow(board_left-ball_x, 2)+Math.pow(board_alterable_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x<board_left && ball_y<board_alterable_top) { ballcornerHit(); } } //-----------------------------挡板碰撞检测结束-------------------------- private void boardHitBallHigher() {//增强 ballUpOrDownHit();//小球Y方向反向,ball_y_speed变为正数 if(ball_y_speed == ballXorYadd ){ ball_y_speed += ballXorYadd;//离开挡板后小球Y方向速度增强 } if( boardYadd > ball_y_speed ){//在线程这一轮,小球上升多少,挡板就上升多少。 board_alterable_top = board_default_top - ball_y_speed; board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } } //检测挡板是否处于“中线”位置,是就随小球上升一步,直至到“上线” private void boardPositionCheck() {//还可直接利用球的位置刷新,board_top与球心相差ball_r if(board_alterable_top < board_default_top && board_alterable_top > board_default_top-boardYadd){ //挡板随球上升 if(board_alterable_top - ball_y_speed >= board_default_top-boardYadd){ board_alterable_top -= ball_y_speed;//挡板上层面 board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } else{ board_alterable_top = board_default_top-boardYadd;//挡板上层面 board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } } } private void ballHitBoardlower() {//减弱 board_alterable_top=board_default_top; board_alterable_bottom=board_default_top+board_thickness;//挡板被打退 ballUpOrDownHit();//小球Y方向反向 if(ball_y_speed==2*ballXorYadd){ ball_y_speed -= ballXorYadd;//小球Y方向速度减弱 } } //砖块碰撞检测开始----------------------------------------------------------- public void hitBrickCheck() { for (int i = 0; i <25 ; i++) { if (brick_exist[i]) { k = i % 5+1;// 1,2,3,4,5循环 j = i / 5+1;// 1,1,1,1,1;2,2,2,2,2,;...;5,5,5,5,5 brick_left = brick_width*(k-1); brick_right = brick_width*k; brick_top = brick_height*j; brick_bottom = brick_height*(j+1); //朝下碰砖的top面 AAAAAAAAAAAAAAAAAAAAA if(ball_x >= brick_left && ball_x <= brick_right && ball_y >= brick_top-ball_r && ball_y < brick_top) { ballUpOrDownHit(); brick_exist[i] = false; score+=4; //朝下正碰2砖中间,i砖右上角检测 if(k!=5 && ball_x == brick_right)//如果不是第5列砖的右侧边 { //如果砖[i+1]存在 if(brick_exist[i+1]){ brick_exist[i+1] = false; score+=4; } } //朝下正碰2砖中间,i砖左上角检测 else if(k!=1 && ball_x == brick_left)//如果不是第1列砖的左侧边 { //如果砖[i-1]存在 if(brick_exist[i-1]){ brick_exist[i-1] = false; score+=4; } } } //朝上碰砖的bottom面 BBBBBBBBBBBBBBBBB else if(ball_x >= brick_left && ball_x <= brick_right && ball_y > brick_bottom&& ball_y <= brick_bottom + ball_r ) { ballUpOrDownHit(); brick_exist[i] = false; score+=4; //朝上正碰2块砖中间--i砖的右下角检测 if(k!=5 && ball_x == brick_right) //如果不是第5列砖的右侧边 { if(brick_exist[i+1]){//如果砖[i+1]存在 brick_exist[i+1] = false; score+=4; } } //朝上正碰2块砖中间--i砖的左下角检测 else if(k!=1 && ball_x == brick_left) //如果不是第1列砖的左侧边 { if(brick_exist[i-1]){//如果砖[i-1]存在 brick_exist[i-1] = false; score+=4; } } } //朝右碰砖的left面CCCCCCCCCCCCCCCCC else if(ball_x >= brick_left -ball_r&&ball_x < brick_left&& ball_y >= brick_top && ball_y <= brick_bottom) { ballLeftOrRightHit(); brick_exist[i] = false; score+=4; //朝右正碰2块砖中间,左下角检测 if(j!=5 && ball_y == brick_bottom)//如果不是第5行砖的下侧边 { if(brick_exist[i+5]){//如果砖[i+5]存在 brick_exist[i+5] = false; score+=4; } } //朝右正碰2块砖中间,左上角检测 else if(j!=1 && ball_y == brick_top)//如果不是第1行砖的上侧边 { if(brick_exist[i-5]){//如果砖[i-5]存在 brick_exist[i-5] = false; score+=4; } } } //朝左碰砖的right面DDDDDDDDDDDDDDDDDD else if(ball_x >= brick_right && ball_x <= brick_right+ball_r&& ball_y >= brick_top && ball_y <= brick_bottom) { ballLeftOrRightHit(); brick_exist[i] = false; score+=4; //朝左正碰2块砖中间,右下角检测 if(j!=5 && ball_y == brick_bottom )//如果不是第5行砖的下侧边 { if(brick_exist[i+5]){//如果砖[i+5]存在 brick_exist[i+5] = false; score+=4; } } //朝左正碰2块砖中间,右上角检测 else if(j!=1 && ball_y == brick_top )//如果不是第1行砖上侧边 { if(brick_exist[i-5]){//如果砖[i-5]存在 brick_exist[i-5] = false; score+=4; } } } ///////////////////////////////////////// //斜碰i砖的左下角EEEEEEEEEEEEEEEEEEEEEEEE else if(( i-1<0||(i-1>=0&&!brick_exist[i-1]) ) && (i+5>=25||(i+5<25&&!brick_exist[i+5]) )&& Math.pow(brick_left-ball_x, 2)+Math.pow(brick_bottom-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_left-ball_r && ball_x<brick_left && ball_y>brick_bottom && ball_y<brick_bottom+ball_r ) { ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的右下角FFFFFFFFFFFFFFFFFFFFFFFFFF else if( (i+1>=25||(i+1<25&&!brick_exist[i+1]) )&& (i+5>=25||(i+5<25&&!brick_exist[i+5]) )&& Math.pow(brick_right-ball_x, 2)+Math.pow(brick_bottom-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_right&&ball_x<brick_right+ball_r&& ball_y>brick_bottom&&ball_y<brick_bottom+ball_r ) { Log.v("----------", "right bottom hit"+i+":"+brick_exist[i]); ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的右上角GGGGGGGGGGGGGGGGGGGGGGGG else if( (i+1>=25||(i+1<25&&!brick_exist[i+1]) )&& (i-5<0||(i-5>0&&!brick_exist[i-5]) )&& Math.pow(brick_right-ball_x, 2)+Math.pow(brick_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_right && ball_x<brick_right+ball_r&& ball_y>brick_top-ball_r && ball_y<brick_top) { ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的左上角HHHHHHHHHHHHHHHHHHHHHHHHHH else if((i-1<0||(i-1>=0&&!brick_exist[i-1])) && (i-5<0||(i-5>=0&&!brick_exist[i-5])) && Math.pow(brick_left-ball_x, 2)+Math.pow(brick_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_left-ball_x && ball_x<brick_left && ball_y>brick_top-ball_r && ball_y<brick_top ) { ballcornerHit(); brick_exist[i] = false; score+=4; } }//end if }//end for }//end hitBrickCheck() //砖块碰撞检测结束----------------------------------------------------------- //------------------------------------------ public boolean gameOver(){ int count = 0; for(boolean s:brick_exist){ if(!s){ count++; } } if(count == 25){ return true; }else{ return false; } } //------------------------------------------ //---------------绘图方法开始------------------------ public void Draw() { // 锁定画布,得到canvas Canvas canvas = mSurfaceHolder.lockCanvas(); if (mSurfaceHolder == null || canvas == null) { return; } // 绘图 Paint mPaint = new Paint(); // 设置取消锯齿效果 mPaint.setAntiAlias(true); mPaint.setColor(Color.BLACK); // 绘制矩形--背景 canvas.drawRect(0, 0, screen_width, brick_height-2, mPaint); mPaint.setColor(Color.GREEN); // 绘制矩形--背景 canvas.drawRect(0, brick_height-2, screen_width, screen_height, mPaint); mPaint.setColor(Color.RED);//设置字体颜色 mPaint.setTextSize(brick_height-7);//设置字体大小 canvas.drawText("得分:"+score, 0, brick_height-7, mPaint); // 绘制顶层挡板````````````````````````````````````````````````````````25号修改 mPaint.setColor(Color.BLACK);//设置颜色 mPaint.setStrokeWidth(4);//设置粗细 canvas.drawLine(0, brick_height-2, screen_width, brick_height-2, mPaint); for (int i = 0; i <25 ; i++) { if (brick_exist[i]) { k = i % 5+1;// 1,2,3,4,5循环 j = i / 5+1;// 1,1,1,1,1;2,2,2,2,2,;...;5,5,5,5,5 brick_left = brick_width*(k-1); brick_right = brick_width*k; brick_top = brick_height*j; brick_bottom = brick_height*(j+1); mPaint.setStyle(Paint.Style.FILL);// 设置实心画笔 mPaint.setColor(Color.YELLOW); canvas.drawRect(brick_left+1, brick_top+1, brick_right-1,brick_bottom-1, mPaint); mPaint.setStyle(Paint.Style.STROKE);// 设置空心画笔 mPaint.setStrokeWidth(2);//设置粗细 mPaint.setColor(Color.BLUE); canvas.drawRect(brick_left+3, brick_top+3, brick_right-3,brick_bottom-3, mPaint); } } // 设置实心画笔 mPaint.setStyle(Paint.Style.FILL); { mPaint.setShader(mRadialGradient); canvas.drawCircle(ball_x, ball_y, ball_r, mPaint); } Paint mPaint2 = new Paint(); // 设置取消锯齿效果 mPaint2.setAntiAlias(true); // 设置实心画笔 mPaint2.setStyle(Paint.Style.FILL); { mPaint2.setColor(Color.BLACK); /* 绘制矩形挡板 */ canvas.drawRect(board_left, board_alterable_top, board_right, board_alterable_bottom,mPaint2); float board2_bottom = screen_height - 2*ball2_r;//164 float board2_top = board2_bottom - 4;//160 //线段端点坐标数组 float x0 = board_left+(board_right-board_left)/4; float y0 = board_alterable_bottom;//440或者444 float springAdd = (board2_top- board_alterable_bottom)/8;//即2.5或者2:弹簧小线段的y向长度 float springWidth = 5.0f;//弹簧小线段的x向长度 float x1 = x0 - springWidth; float y1 = y0 + springAdd; float x2 = x0 + springWidth; float y2 = y0 + 3*springAdd; float x3 = x1 ; float y3 = y0 + 5*springAdd; float x4 = x2; float y4 = y0 + 7*springAdd; float x5 = x0 ; float y5 = board2_top;//即460 float between_spring = (board_right-board_left)/2; float pts[] = { x0,y0,x1,y1, x1,y1,x2,y2, x2,y2,x3,y3, x3,y3,x4,y4, x4,y4,x5,y5}; float pts2[] = {x0+between_spring,y0, x1+between_spring,y1, x1+between_spring,y1, x2+between_spring,y2, x2+between_spring,y2, x3+between_spring,y3, x3+between_spring,y3, x4+between_spring,y4, x4+between_spring,y4, x5+between_spring,y5}; mPaint2.setStrokeWidth(2);//设置弹簧粗细 //绘制2个弹簧 canvas.drawLines(pts, mPaint2); canvas.drawLines(pts2, mPaint2); //绘制下层挡板 canvas.drawRect(board_left, board2_top, board_right, board2_bottom,mPaint2); mPaint2.setColor(Color.BLACK);// // 绘制最下面的两个“轮子”(圆心x,圆心y,半径r,p) canvas.drawCircle(board_left+ball2_r, screen_height-ball2_r, ball2_r, mPaint2);//圆 canvas.drawCircle(board_right-ball2_r, screen_height-ball2_r, ball2_r, mPaint2); mPaint2.setColor(Color.WHITE);// canvas.drawPoint(board_left+ball2_r, screen_height-ball2_r, mPaint2);//绘制左轮轮心 canvas.drawPoint(board_right-ball2_r, screen_height-ball2_r, mPaint2);//绘制右轮轮心 }//实心画笔mPaint2结束 if(gameOver()){ // mbLoop = false;//注释掉的话GAME OVER后也可重启 ball_isRun = false; mPaint2.setColor(Color.BLACK);//设置字体颜色 mPaint2.setTextSize(40.0f);//设置字体大小 canvas.drawText("GAME OVER", screen_width/32+40, screen_height/16*9-70, mPaint2); mPaint2.setTextSize(20.0f);//设置字体大小 canvas.drawText("Press \"MENU\" button to restart,", screen_width/32, //320/32=10 screen_height/16*9, //480/16=30,30*9=270 mPaint2); canvas.drawText("Press \"BACK\" button to exit.", screen_width/32, //320/32=10 screen_height/16*10, //480/16=30,30*10=300 mPaint2); } // 绘制后解锁,绘制后必须解锁才能显示 mSurfaceHolder.unlockCanvasAndPost(canvas); }// end of Draw() //---------------------绘图方法结束----------------------------------------------- // 在surface的大小发生改变时激发 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } // 在surface创建时激发 public void surfaceCreated(SurfaceHolder holder) { new Thread(this).start();// 开启绘图线程 } // 在surface销毁时激发 public void surfaceDestroyed(SurfaceHolder holder) { // 停止循环 mbLoop = false; } } 下个界面的代码是 package ab.cc; import android.app.Activity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.Window; import android.view.WindowManager; public class BaomingActivity extends Activity { BallView myView; static int screenWidth; static int screenHeight; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 定义DisplayMetrics对象 */ DisplayMetrics dm = new DisplayMetrics(); /* 取得窗口属性 */ getWindowManager().getDefaultDisplay().getMetrics(dm); /* 窗口的宽度 */ screenWidth = dm.widthPixels; /* 窗口的高度 */ screenHeight = dm.heightPixels; // setTitle("宽"+screenWidth+" 高"+screenHeight); /* 设置为无标题栏 */ requestWindowFeature(Window.FEATURE_NO_TITLE); /* 设置为全屏模式 */ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); myView = new BallView(this); //设置显示GameSurfaceView视图 setContentView(myView); }//end of onCreate() //触笔事件 public boolean onTouchEvent(MotionEvent event) { return true; } //按键按下事件 public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { //菜单按键-设为初始菜单 case KeyEvent.KEYCODE_MENU: myView.resetGame(); //重新开始 break; //中间按键 case KeyEvent.KEYCODE_DPAD_CENTER: myView.ball_isRun = !myView.ball_isRun;//开始//暂停 break; //左方向键 case KeyEvent.KEYCODE_DPAD_LEFT: if(myView.ball_isRun){ if(myView.board_left<=myView.board_x_move) { myView.board_left=0; myView.board_right=myView.board_length; }else{ myView.board_left-=myView.board_x_move; myView.board_right-=myView.board_x_move;} } break; //右方向键 case KeyEvent.KEYCODE_DPAD_RIGHT: if(myView.ball_isRun){ if(screenWidth-myView.board_right<=myView.board_x_move ) { myView.board_left=screenWidth-myView.board_length; myView.board_right=screenWidth; }else{ myView.board_left+=myView.board_x_move; myView.board_right+=myView.board_x_move; } } break; //上方向键 case KeyEvent.KEYCODE_DPAD_UP: if(myView.ball_isRun){ if( myView.board_alterable_top==myView.board_default_top) { myView.board_alterable_top-=myView.boardYadd; myView.board_alterable_bottom-=myView.boardYadd; } } break; //下方向键 case KeyEvent.KEYCODE_DPAD_DOWN: if(myView.ball_isRun){ if( myView.board_alterable_top==myView.board_default_top-myView.boardYadd ) { myView.board_alterable_top=myView.board_default_top; myView.board_alterable_bottom=myView.board_alterable_top+myView.board_thickness; } } break; //返回键 case KeyEvent.KEYCODE_BACK: this.finish(); break; }//end switch return false; } //按键弹起事件 public boolean onKeyUp(int keyCode, KeyEvent event) { return true; } public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { return true; } }

监听ImageView没有反应

监听ImageView时用View.OnClickListener接口,然后重写OnClick(View v)没有反应。 @Override public void onClick(View v) { switch (v.getId()){ case R.id.qq: explosionField.explode(v); explosionField.setOnMyEvent(this); break; case R.id.qzone: explosionField.explode(v); break; } 这种方法就可以, iv_qq = (ImageView)findViewById(R.id.qq); iv_qq.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { explosionField.explode(v); } }); 为什么呢?

Android中关于背景图片的问题,求助。

主程序中有俩个.java文件,分别如下。在layout中设置了android:background="@drawable/cc",然而被没有出现背景图片,还是黑兮兮的一片。求大牛帮助,不甚感激。 代码如下: **MainActivity.java** package com.example.homework; import android.app.Activity; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class MainActivity extends Activity { public static MainActivity instance; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = this; //设置全屏 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); //显示自定义的SurfaceView视图 setContentView(new MySurfaceView(this)); } } **MySurfaceView.java文件** package com.example.homework; import android.app.Service; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.SurfaceHolder.Callback; public class MySurfaceView extends SurfaceView implements Callback, Runnable { private SurfaceHolder sfh; private Paint paint; private Thread th; private boolean flag; private Canvas canvas; private int screenW, screenH; //声明一个传感器管理器 private SensorManager sm; //声明一个传感器 private Sensor sensor; //声明一个传感器监听器 private SensorEventListener mySensorListener; //圆形的X,Y坐标 private int arc_x, arc_y; //传感器的xyz值 private float x = 0, y = 0, z = 0; /** * SurfaceView初始化函数 */ public MySurfaceView(Context context) { super(context); sfh = this.getHolder(); sfh.addCallback(this); paint = new Paint(); paint.setColor(Color.WHITE); paint.setAntiAlias(true); setFocusable(true); //获取传感器管理类实例 sm = (SensorManager) MainActivity.instance.getSystemService(Service.SENSOR_SERVICE); //实例一个重力传感器实例 sensor = sm.getDefaultSensor(Sensor.TYPE_GRAVITY); //实例传感器监听器 mySensorListener = new SensorEventListener() { @Override //传感器获取值发生改变时在响应此函数 public void onSensorChanged(SensorEvent event) { x = event.values[0]; //x>0 说明当前手机左翻 x<0右翻 y = event.values[1]; //y>0 说明当前手机下翻 y<0上翻 z = event.values[2]; //z>0 手机屏幕朝上 z<0 手机屏幕朝下 arc_x -= x; arc_y += y; } @Override //传感器的精度发生改变时响应此函数 public void onAccuracyChanged(Sensor sensor, int accuracy) { } }; //为传感器注册监听器 sm.registerListener(mySensorListener, sensor, SensorManager.SENSOR_DELAY_NORMAL); } /** * SurfaceView视图创建,响应此函数 */ @Override public void surfaceCreated(SurfaceHolder holder) { screenW = this.getWidth(); screenH = this.getHeight(); flag = true; //实例线程 th = new Thread(this); //启动线程 th.start(); } /** * 游戏绘图 */ public void myDraw() { try { canvas = sfh.lockCanvas(); if (canvas != null) { canvas.drawColor(Color.BLACK); paint.setColor(Color.RED); canvas.drawArc(new RectF(arc_x, arc_y, arc_x + 50, arc_y + 50), 0, 360, true, paint); paint.setColor(Color.YELLOW); canvas.drawText("当前重力传感器的值:", arc_x - 50, arc_y - 30, paint); canvas.drawText("x=" + x+" "+ "y=" + y +" "+ "z=" + z, arc_x - 50, arc_y, paint); String temp_str = "温馨提示: "; String temp_str2 = ""; String temp_str3 = ""; if (x < 1 && x > -1 && y < 1 && y > -1) { temp_str2 += "当前手机处于水平放置的状态"; if (z > 0) { temp_str3 += "并且屏幕朝上"+" "+"X轴的测试值:" + x + " " + "Y轴的测试值:" + y + " " + "Z轴的测试值:" + z; } else { temp_str3 += "并且屏幕朝下,提示别躺着玩手机,对眼睛不好哟~"+" "+"X轴的测试值:" + x + " " + "Y轴的测试值:" + y + " " + "Z轴的测试值:" + z; } } else { if (x > 1) { temp_str2 += "当前手机处于向左翻的状态"+" "; } else if (x < -1) { temp_str2 += "当前手机处于向右翻的状态"+" "; } if (y > 1) { temp_str2 += "当前手机处于向下翻的状态"+" "; } else if (y < -1) { temp_str2 += "当前手机处于向上翻的状态"+" "; } if (z > 0) { temp_str3 += "并且屏幕朝上"+" "+"X轴的测试值:" + x + " " + "Y轴的测试值:" + y + " " + "Z轴的测试值:" + z; } else { temp_str3 += "并且屏幕朝下,提示别躺着玩手机,对眼睛不好哟~"+" "+"X轴的测试值:" + x + " " + "Y轴的测试值:" + y + " " + "Z轴的测试值:" + z; } } paint.setTextSize(10); canvas.drawText(temp_str, 0, 50, paint); canvas.drawText(temp_str2, 0, 80, paint); canvas.drawText(temp_str3, 0, 110, paint); } } catch (Exception e) { // TODO: handle exception } finally { if (canvas != null) sfh.unlockCanvasAndPost(canvas); } } /** * 触屏事件监听 */ @Override public boolean onTouchEvent(MotionEvent event) { return true; } /** * 按键事件监听 */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return super.onKeyDown(keyCode, event); } /** * 游戏逻辑 */ private void logic() { } @Override public void run() { while (flag) { long start = System.currentTimeMillis(); myDraw(); logic(); long end = System.currentTimeMillis(); try { if (end - start < 50) { Thread.sleep(50 - (end - start)); } } catch (InterruptedException e) { e.printStackTrace(); } } } /** * SurfaceView视图状态发生改变,响应此函数 */ @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } /** * SurfaceView视图消亡时,响应此函数 */ @Override public void surfaceDestroyed(SurfaceHolder holder) { flag = false; } } 以下是布局文件代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/cc" > </LinearLayout>

android fragment内部控件跳转fragment 如何替换标题

遇到一个问题 比如 mainActivity 里面有3个fragment,其中一个个人中心fragment里面有多个控件,点击其中一个控件跳转到消息的fragment,但是标题还是显示个人中心 ,要怎么切换标题?代码怎么操作 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //声明使用自定义标题 setContentView(R.layout.activity_main); // 注意顺序 //设置窗体样式 getWindow().setFeatureInt( Window.FEATURE_CUSTOM_TITLE, //设置此样式为自定义样式 R.layout.title //设置对应的布局 );//自定义布局赋值 这个是mainActivity 里面可以这样写 但是在个人中心 fragment就不能这样 有什么方法可以替换标题呢 个人中心可以切换标题 titleName.setText(getResources().getString(R.string.person_home)); btnBack.setVisibility(View.VISIBLE); btnBack.setText("注销"); 但是后面在 个人中心fragment里面就不懂怎么操作了

Android 怎么将主程序添加到欢迎界面里面

我做好了一个欢迎界面,并且做了下按钮触发,里面什么都还没有,我这边有一个游戏主程序,应该怎么样才能合理的添加进去呢? 添加的结果就是 点击这个按钮 就进入这个主程序。下面是代码 这个是我的欢迎界面的代码 package sen.tan; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; public class dazhuankuaiActivity extends Activity { BallView myview; public static int screenWidth ; public static int screenHeight; private TextView textview; Button kaishi,jieshu,guanyu; ImageView image; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String string = "欢迎进入疯狂打砖块游戏"; image = (ImageView) this.findViewById(R.id.image); image.setImageResource(R.drawable.img1); textview =(TextView) this.findViewById(R.id.textview); textview.setTextSize(20); textview.setTextColor(Color.GREEN); textview.setBackgroundColor(Color.RED); textview.setText(string); kaishi=(Button)findViewById(R.id.button1); guanyu=(Button)findViewById(R.id.button2); jieshu=(Button)findViewById(R.id.button3); kaishi.setWidth(250); guanyu.setWidth(200); jieshu.setWidth(150); kaishi.setTextSize(35); guanyu.setTextSize(29); jieshu.setTextSize(24); jieshu.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v) { dazhuankuaiActivity.this.finish(); } }); guanyu.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ textview.setText("本游戏由xxx制作,此游戏控制左右按键,来回移动挡板,不让小球掉落,当小球把上方砖块全部打完时,游戏胜利"); } }); kaishi.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v) { } }); 下面是我找到的主程序 package ab.cc; import android.app.Activity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.Window; import android.view.WindowManager; public class BaomingActivity extends Activity { BallView myView; static int screenWidth; static int screenHeight; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 定义DisplayMetrics对象 */ DisplayMetrics dm = new DisplayMetrics(); /* 取得窗口属性 */ getWindowManager().getDefaultDisplay().getMetrics(dm); /* 窗口的宽度 */ screenWidth = dm.widthPixels; /* 窗口的高度 */ screenHeight = dm.heightPixels; // setTitle("宽"+screenWidth+" 高"+screenHeight); /* 设置为无标题栏 */ requestWindowFeature(Window.FEATURE_NO_TITLE); /* 设置为全屏模式 */ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); myView = new BallView(this); //设置显示GameSurfaceView视图 setContentView(myView); }//end of onCreate() //触笔事件 public boolean onTouchEvent(MotionEvent event) { return true; } //按键按下事件 public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { //菜单按键-设为初始菜单 case KeyEvent.KEYCODE_MENU: myView.resetGame(); //重新开始 break; //中间按键 case KeyEvent.KEYCODE_DPAD_CENTER: myView.ball_isRun = !myView.ball_isRun;//开始//暂停 break; //左方向键 case KeyEvent.KEYCODE_DPAD_LEFT: if(myView.ball_isRun){ if(myView.board_left<=myView.board_x_move) { myView.board_left=0; myView.board_right=myView.board_length; }else{ myView.board_left-=myView.board_x_move; myView.board_right-=myView.board_x_move;} } break; //右方向键 case KeyEvent.KEYCODE_DPAD_RIGHT: if(myView.ball_isRun){ if(screenWidth-myView.board_right<=myView.board_x_move ) { myView.board_left=screenWidth-myView.board_length; myView.board_right=screenWidth; }else{ myView.board_left+=myView.board_x_move; myView.board_right+=myView.board_x_move; } } break; //上方向键 case KeyEvent.KEYCODE_DPAD_UP: if(myView.ball_isRun){ if( myView.board_alterable_top==myView.board_default_top) { myView.board_alterable_top-=myView.boardYadd; myView.board_alterable_bottom-=myView.boardYadd; } } break; //下方向键 case KeyEvent.KEYCODE_DPAD_DOWN: if(myView.ball_isRun){ if( myView.board_alterable_top==myView.board_default_top-myView.boardYadd ) { myView.board_alterable_top=myView.board_default_top; myView.board_alterable_bottom=myView.board_alterable_top+myView.board_thickness; } } break; //返回键 case KeyEvent.KEYCODE_BACK: this.finish(); break; }//end switch return false; } //按键弹起事件 public boolean onKeyUp(int keyCode, KeyEvent event) { return true; } public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { return true; } } package ab.cc; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RadialGradient; import android.graphics.Shader; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; public class BallView extends SurfaceView implements SurfaceHolder.Callback, Runnable { //线程延时控制 final int ball_sleep=1;//毫秒,延时越大,球速越慢 final int ball_r= 8;//小球半径 final float ball2_r= 8;//底下滚珠小球半径 final int ballXorYadd = 4;//小球的基本位移。测试可行值:2,4 //获取屏幕宽度和高度 int screen_width;//320; int screen_height;//480; //砖的属性 int brick_width;//每块砖宽 int brick_height;//每块砖高 boolean brick_exist[];//砖是否存在 int k ;// 列//到for循环里才初始化 int j ;// 行 int brick_left = brick_width*(k-1);//到判断语句才初始化 int brick_right = brick_width*k; int brick_top = brick_height*j; int brick_bottom = brick_height*(j+1); //挡板的属性 int board_length;//挡板长度:80比较合适,可以随意修改,但别超过screen_width final int boardYadd = 16;//按上下键时挡板y方向位移量。经验证4、8、16可以,12不行 final int board_x_move = 30;//挡板x方向位移量:可以随意自定义 int board_left;//挡板左侧(可变) int board_right;//挡板右侧(可变) int board_thickness;//挡板厚度 int board_default_top;//即435,挡板的top面初始位置 int board_alterable_top;//挡板上侧(可变) int board_alterable_bottom;//挡板下侧(可变) int ball_default_x;//球的初始x坐标 int ball_default_y;//球的初始y坐标 //球的即时坐标(可变): int ball_x;//球心横坐标 int ball_y;//球心纵坐标 //球的前一步的y坐标 int ball_previous_y; int ball_x_speed;//球的横向偏移量//可变 int ball_y_speed;//球的纵向偏移量//可变 boolean ball_isRun;//球是否在动 // 控制循环 boolean mbLoop; // 定义SurfaceHolder对象 SurfaceHolder mSurfaceHolder = null; //获得分数 int score; /* 唤醒渐变渲染 */ Shader mRadialGradient = null; //------------------------------------------------------------------------------------------------------// public BallView(Context context) { super(context); // 实例化SurfaceHolder mSurfaceHolder = this.getHolder(); // 添加回调 mSurfaceHolder.addCallback(this); this.setFocusable(true); //获取屏幕宽度和高度 screen_width = BaomingActivity.screenWidth;//320 screen_height = BaomingActivity.screenHeight;//480 //砖的属性 brick_width = screen_width/5;//每块砖宽64 brick_height = screen_height/15;//每块砖高32 //挡板的属性 board_length = screen_width/4;//挡板长度:80比较合适,可以随意修改,但别超过screen_width board_left = (screen_width-board_length)/2;//挡板左侧(可变) board_right = (screen_width+board_length)/2;//挡板右侧(可变) board_thickness = 5;//挡板厚度 board_default_top = 13*screen_height/15;//即435,挡板的top面初始位置 board_alterable_top = board_default_top;//挡板上侧(可变) board_alterable_bottom = board_alterable_top+board_thickness;//挡板下侧(可变) ball_default_x = screen_width/2;//球的初始x坐标 ball_default_y = board_default_top - ball_r;//球的初始y坐标 //球的即时坐标(可变): ball_x = ball_default_x; ball_y = ball_default_y; //球的前一步的y坐标 ball_previous_y = 0; ball_x_speed = ballXorYadd;//球的横向偏移量 ball_y_speed = ballXorYadd;//球的纵向偏移量 mbLoop = true; ball_isRun = false; score=0; brick_exist = new boolean[25]; for (int i = 0; i < 25; i++) { brick_exist[i] = true; } /* 构建RadialGradient对象,设置半径的属性 */ mRadialGradient = new RadialGradient(ball_x, ball_y, ball_r,//球中心坐标x,y,半径r new int[]{Color.WHITE,Color.BLUE,Color.GREEN,Color.RED,Color.YELLOW},//颜色数组 null,//颜色数组中每一种颜色对应的相对位置,为空的话就是平均分布,由中心向外排布 Shader.TileMode.REPEAT);//渲染模式:重复 } public void resetGame(){ ball_isRun = false; score =0;//分数 ball_x_speed = ballXorYadd;//球的横向偏移量 ball_y_speed = ballXorYadd;//球的纵向偏移量 ball_x = screen_width/2;//球心起始横坐标 ball_y = board_default_top - ball_r;//球心起始纵坐标 board_left = (screen_width-board_length)/2;//挡板左侧 board_right = (screen_width+board_length)/2;//挡板右侧 board_alterable_top = board_default_top;//挡板上侧 board_alterable_bottom = board_alterable_top+board_thickness;//挡板下侧 for (int i = 0; i < 25; i++) { brick_exist[i] = true; } } //---------------------------------绘图循环开始---------------------------------- public void run() { while (mbLoop&&!Thread.currentThread().isInterrupted()) { try { Thread.sleep(ball_sleep); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } //球的前一步y坐标 ball_previous_y = ball_y; if (ball_isRun) { ballRunning();// 让小球移动 boardPositionCheck();//检测挡板是否处于“中线”位置,是就随小球上升一步,直至到“上线” hitWallCheck();//墙壁碰撞检测 hitBoardCheck();//挡板碰撞检测 hitBrickCheck();//砖块碰撞检测 } synchronized (mSurfaceHolder) { Draw(); } } } //---------------------------------绘图循环结束---------------------------------- //------------------------------------------------------------------------------ //让小球移动 public void ballRunning() { ball_x += ball_x_speed; ball_y -= ball_y_speed; } //朝左或朝右碰撞后小球水平方向逆向 public void ballLeftOrRightHit() { ball_x_speed *= -1; } //朝上或朝下碰撞后小球竖直方向逆向 public void ballUpOrDownHit() { ball_y_speed *= -1; } public void ballcornerHit() { ball_x_speed *= -1; ball_y_speed *= -1; } public void ballStraightUp() {//功能没实现,这是多余代码 ball_x_speed = 0;//注意在其他地方恢复 ball_y_speed *= -1; } //-------------------墙壁碰撞检测开始------------------------------------- public void hitWallCheck() { // 左碰墙 if (ball_x <= ball_r && ball_y >= ball_r && ball_y <= screen_height) { ballLeftOrRightHit(); // 右碰墙 } if (ball_x >= screen_width - ball_r && //不能写为 else if,因为可能恰好碰到角落。 ball_y >= ball_r && ball_y <= screen_height) { ballLeftOrRightHit(); } // 上碰墙 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && ball_y <= ball_r + brick_height) //、、、、、、、、、、、、、、、25号修改 { ballUpOrDownHit(); } // 下碰墙 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && ball_y >= screen_height-ball_r) { ballUpOrDownHit(); if(score<=10){ score = 0; } else score-=10; } } //-------------------墙壁碰撞检测结束------------------------------------- //-----------------------------挡板碰撞检测开始--------------------------- public void hitBoardCheck() { // 下碰挡板正面 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && //在屏幕内,起码条件 ball_x >= board_left && ball_x <= board_right && //在挡板X域上方 ball_y == board_alterable_top - ball_r &&//球面与挡板相切 ball_previous_y <= board_alterable_top - ball_r //确定球是从上方下落 ) { if(board_alterable_top==board_default_top-boardYadd ){//如果弹簧伸张,挡板位于上线 ballHitBoardlower();//作用:ball_y_move减小;挡板被打下;小球Y向运动反向 } else if(board_alterable_top==board_default_top){//如果弹簧压缩,挡板位于下线 boardHitBallHigher();//作用:ball_y_move增加;挡板弹上;小球Y向运动反向 } } //斜碰挡板右上角//经验证有效 else if(Math.pow(board_right-ball_x, 2)+Math.pow(board_alterable_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>board_right && ball_y<board_alterable_top) { ballcornerHit(); } //斜碰挡板的左上角//经验证有效 else if(Math.pow(board_left-ball_x, 2)+Math.pow(board_alterable_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x<board_left && ball_y<board_alterable_top) { ballcornerHit(); } } //-----------------------------挡板碰撞检测结束-------------------------- private void boardHitBallHigher() {//增强 ballUpOrDownHit();//小球Y方向反向,ball_y_speed变为正数 if(ball_y_speed == ballXorYadd ){ ball_y_speed += ballXorYadd;//离开挡板后小球Y方向速度增强 } if( boardYadd > ball_y_speed ){//在线程这一轮,小球上升多少,挡板就上升多少。 board_alterable_top = board_default_top - ball_y_speed; board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } } //检测挡板是否处于“中线”位置,是就随小球上升一步,直至到“上线” private void boardPositionCheck() {//还可直接利用球的位置刷新,board_top与球心相差ball_r if(board_alterable_top < board_default_top && board_alterable_top > board_default_top-boardYadd){ //挡板随球上升 if(board_alterable_top - ball_y_speed >= board_default_top-boardYadd){ board_alterable_top -= ball_y_speed;//挡板上层面 board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } else{ board_alterable_top = board_default_top-boardYadd;//挡板上层面 board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } } } private void ballHitBoardlower() {//减弱 board_alterable_top=board_default_top; board_alterable_bottom=board_default_top+board_thickness;//挡板被打退 ballUpOrDownHit();//小球Y方向反向 if(ball_y_speed==2*ballXorYadd){ ball_y_speed -= ballXorYadd;//小球Y方向速度减弱 } } //砖块碰撞检测开始----------------------------------------------------------- public void hitBrickCheck() { for (int i = 0; i <25 ; i++) { if (brick_exist[i]) { k = i % 5+1;// 1,2,3,4,5循环 j = i / 5+1;// 1,1,1,1,1;2,2,2,2,2,;...;5,5,5,5,5 brick_left = brick_width*(k-1); brick_right = brick_width*k; brick_top = brick_height*j; brick_bottom = brick_height*(j+1); //朝下碰砖的top面 AAAAAAAAAAAAAAAAAAAAA if(ball_x >= brick_left && ball_x <= brick_right && ball_y >= brick_top-ball_r && ball_y < brick_top) { ballUpOrDownHit(); brick_exist[i] = false; score+=4; //朝下正碰2砖中间,i砖右上角检测 if(k!=5 && ball_x == brick_right)//如果不是第5列砖的右侧边 { //如果砖[i+1]存在 if(brick_exist[i+1]){ brick_exist[i+1] = false; score+=4; } } //朝下正碰2砖中间,i砖左上角检测 else if(k!=1 && ball_x == brick_left)//如果不是第1列砖的左侧边 { //如果砖[i-1]存在 if(brick_exist[i-1]){ brick_exist[i-1] = false; score+=4; } } } //朝上碰砖的bottom面 BBBBBBBBBBBBBBBBB else if(ball_x >= brick_left && ball_x <= brick_right && ball_y > brick_bottom&& ball_y <= brick_bottom + ball_r ) { ballUpOrDownHit(); brick_exist[i] = false; score+=4; //朝上正碰2块砖中间--i砖的右下角检测 if(k!=5 && ball_x == brick_right) //如果不是第5列砖的右侧边 { if(brick_exist[i+1]){//如果砖[i+1]存在 brick_exist[i+1] = false; score+=4; } } //朝上正碰2块砖中间--i砖的左下角检测 else if(k!=1 && ball_x == brick_left) //如果不是第1列砖的左侧边 { if(brick_exist[i-1]){//如果砖[i-1]存在 brick_exist[i-1] = false; score+=4; } } } //朝右碰砖的left面CCCCCCCCCCCCCCCCC else if(ball_x >= brick_left -ball_r&&ball_x < brick_left&& ball_y >= brick_top && ball_y <= brick_bottom) { ballLeftOrRightHit(); brick_exist[i] = false; score+=4; //朝右正碰2块砖中间,左下角检测 if(j!=5 && ball_y == brick_bottom)//如果不是第5行砖的下侧边 { if(brick_exist[i+5]){//如果砖[i+5]存在 brick_exist[i+5] = false; score+=4; } } //朝右正碰2块砖中间,左上角检测 else if(j!=1 && ball_y == brick_top)//如果不是第1行砖的上侧边 { if(brick_exist[i-5]){//如果砖[i-5]存在 brick_exist[i-5] = false; score+=4; } } } //朝左碰砖的right面DDDDDDDDDDDDDDDDDD else if(ball_x >= brick_right && ball_x <= brick_right+ball_r&& ball_y >= brick_top && ball_y <= brick_bottom) { ballLeftOrRightHit(); brick_exist[i] = false; score+=4; //朝左正碰2块砖中间,右下角检测 if(j!=5 && ball_y == brick_bottom )//如果不是第5行砖的下侧边 { if(brick_exist[i+5]){//如果砖[i+5]存在 brick_exist[i+5] = false; score+=4; } } //朝左正碰2块砖中间,右上角检测 else if(j!=1 && ball_y == brick_top )//如果不是第1行砖上侧边 { if(brick_exist[i-5]){//如果砖[i-5]存在 brick_exist[i-5] = false; score+=4; } } } ///////////////////////////////////////// //斜碰i砖的左下角EEEEEEEEEEEEEEEEEEEEEEEE else if(( i-1<0||(i-1>=0&&!brick_exist[i-1]) ) && (i+5>=25||(i+5<25&&!brick_exist[i+5]) )&& Math.pow(brick_left-ball_x, 2)+Math.pow(brick_bottom-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_left-ball_r && ball_x<brick_left && ball_y>brick_bottom && ball_y<brick_bottom+ball_r ) { ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的右下角FFFFFFFFFFFFFFFFFFFFFFFFFF else if( (i+1>=25||(i+1<25&&!brick_exist[i+1]) )&& (i+5>=25||(i+5<25&&!brick_exist[i+5]) )&& Math.pow(brick_right-ball_x, 2)+Math.pow(brick_bottom-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_right&&ball_x<brick_right+ball_r&& ball_y>brick_bottom&&ball_y<brick_bottom+ball_r ) { Log.v("----------", "right bottom hit"+i+":"+brick_exist[i]); ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的右上角GGGGGGGGGGGGGGGGGGGGGGGG else if( (i+1>=25||(i+1<25&&!brick_exist[i+1]) )&& (i-5<0||(i-5>0&&!brick_exist[i-5]) )&& Math.pow(brick_right-ball_x, 2)+Math.pow(brick_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_right && ball_x<brick_right+ball_r&& ball_y>brick_top-ball_r && ball_y<brick_top) { ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的左上角HHHHHHHHHHHHHHHHHHHHHHHHHH else if((i-1<0||(i-1>=0&&!brick_exist[i-1])) && (i-5<0||(i-5>=0&&!brick_exist[i-5])) && Math.pow(brick_left-ball_x, 2)+Math.pow(brick_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_left-ball_x && ball_x<brick_left && ball_y>brick_top-ball_r && ball_y<brick_top ) { ballcornerHit(); brick_exist[i] = false; score+=4; } }//end if }//end for }//end hitBrickCheck() //砖块碰撞检测结束----------------------------------------------------------- //------------------------------------------ public boolean gameOver(){ int count = 0; for(boolean s:brick_exist){ if(!s){ count++; } } if(count == 25){ return true; }else{ return false; } } //------------------------------------------ //---------------绘图方法开始------------------------ public void Draw() { // 锁定画布,得到canvas Canvas canvas = mSurfaceHolder.lockCanvas(); if (mSurfaceHolder == null || canvas == null) { return; } // 绘图 Paint mPaint = new Paint(); // 设置取消锯齿效果 mPaint.setAntiAlias(true); mPaint.setColor(Color.GREEN); // 绘制矩形--背景 canvas.drawRect(0, 0, screen_width, brick_height-2, mPaint); mPaint.setColor(Color.MAGENTA); // 绘制矩形--背景 canvas.drawRect(0, brick_height-2, screen_width, screen_height, mPaint); mPaint.setColor(Color.RED);//设置字体颜色 mPaint.setTextSize(brick_height-7);//设置字体大小 canvas.drawText("得分:"+score, 0, brick_height-7, mPaint); // 绘制顶层挡板````````````````````````````````````````````````````````25号修改 mPaint.setColor(Color.BLACK);//设置颜色 mPaint.setStrokeWidth(4);//设置粗细 canvas.drawLine(0, brick_height-2, screen_width, brick_height-2, mPaint); for (int i = 0; i <25 ; i++) { if (brick_exist[i]) { k = i % 5+1;// 1,2,3,4,5循环 j = i / 5+1;// 1,1,1,1,1;2,2,2,2,2,;...;5,5,5,5,5 brick_left = brick_width*(k-1); brick_right = brick_width*k; brick_top = brick_height*j; brick_bottom = brick_height*(j+1); mPaint.setStyle(Paint.Style.FILL);// 设置实心画笔 mPaint.setColor(Color.BLACK); canvas.drawRect(brick_left+1, brick_top+1, brick_right-1,brick_bottom-1, mPaint); mPaint.setStyle(Paint.Style.STROKE);// 设置空心画笔 mPaint.setStrokeWidth(2);//设置粗细 mPaint.setColor(Color.RED); canvas.drawRect(brick_left+3, brick_top+3, brick_right-3,brick_bottom-3, mPaint); } } // 设置实心画笔 mPaint.setStyle(Paint.Style.FILL); { mPaint.setShader(mRadialGradient); canvas.drawCircle(ball_x, ball_y, ball_r, mPaint); } Paint mPaint2 = new Paint(); // 设置取消锯齿效果 mPaint2.setAntiAlias(true); // 设置实心画笔 mPaint2.setStyle(Paint.Style.FILL); { mPaint2.setColor(Color.BLACK); /* 绘制矩形挡板 */ canvas.drawRect(board_left, board_alterable_top, board_right, board_alterable_bottom,mPaint2); float board2_bottom = screen_height - 2*ball2_r;//164 float board2_top = board2_bottom - 4;//160 //线段端点坐标数组 float x0 = board_left+(board_right-board_left)/4; float y0 = board_alterable_bottom;//440或者444 float springAdd = (board2_top- board_alterable_bottom)/8;//即2.5或者2:弹簧小线段的y向长度 float springWidth = 5.0f;//弹簧小线段的x向长度 float x1 = x0 - springWidth; float y1 = y0 + springAdd; float x2 = x0 + springWidth; float y2 = y0 + 3*springAdd; float x3 = x1 ; float y3 = y0 + 5*springAdd; float x4 = x2; float y4 = y0 + 7*springAdd; float x5 = x0 ; float y5 = board2_top;//即460 float between_spring = (board_right-board_left)/2; float pts[] = { x0,y0,x1,y1, x1,y1,x2,y2, x2,y2,x3,y3, x3,y3,x4,y4, x4,y4,x5,y5}; float pts2[] = {x0+between_spring,y0, x1+between_spring,y1, x1+between_spring,y1, x2+between_spring,y2, x2+between_spring,y2, x3+between_spring,y3, x3+between_spring,y3, x4+between_spring,y4, x4+between_spring,y4, x5+between_spring,y5}; mPaint2.setStrokeWidth(2);//设置弹簧粗细 //绘制2个弹簧 canvas.drawLines(pts, mPaint2); canvas.drawLines(pts2, mPaint2); //绘制下层挡板 canvas.drawRect(board_left, board2_top, board_right, board2_bottom,mPaint2); mPaint2.setColor(Color.BLACK);// // 绘制最下面的两个“轮子”(圆心x,圆心y,半径r,p) canvas.drawCircle(board_left+ball2_r, screen_height-ball2_r, ball2_r, mPaint2);//圆 canvas.drawCircle(board_right-ball2_r, screen_height-ball2_r, ball2_r, mPaint2); mPaint2.setColor(Color.WHITE);// }//实心画笔mPaint2结束 if(gameOver()){ // mbLoop = false;//注释掉的话GAME OVER后也可重启 ball_isRun = false; mPaint2.setColor(Color.BLACK);//设置字体颜色 mPaint2.setTextSize(40.0f);//设置字体大小 canvas.drawText("GAME OVER", screen_width/32+40, screen_height/16*9-70, mPaint2); mPaint2.setTextSize(20.0f);//设置字体大小 canvas.drawText("Press \"MENU\" button to restart,", screen_width/32, //320/32=10 screen_height/16*9, //480/16=30,30*9=270 mPaint2); canvas.drawText("Press \"BACK\" button to exit.", screen_width/32, //320/32=10 screen_height/16*10, //480/16=30,30*10=300 mPaint2); } // 绘制后解锁,绘制后必须解锁才能显示 mSurfaceHolder.unlockCanvasAndPost(canvas); }// end of Draw() //---------------------绘图方法结束----------------------------------------------- // 在surface的大小发生改变时激发 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } // 在surface创建时激发 public void surfaceCreated(SurfaceHolder holder) { new Thread(this).start();// 开启绘图线程 } // 在surface销毁时激发 public void surfaceDestroyed(SurfaceHolder holder) { // 停止循环 mbLoop = false; } } 能否回答的详细一点,学的时间短,求帮忙

Android打砖块代码 其中系统说格式错误 求帮助

我这边有一个打砖块代码,我将它移植到我的按钮事件触发里 提示我格式错误 下面前两个是打砖块代码 ,后两个是转到我的里面之后的, 标注了,请帮忙。 package ab.cc; import android.app.Activity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.Window; import android.view.WindowManager; public class BaomingActivity extends Activity { BallView myView; static int screenWidth; static int screenHeight; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 定义DisplayMetrics对象 */ DisplayMetrics dm = new DisplayMetrics(); /* 取得窗口属性 */ getWindowManager().getDefaultDisplay().getMetrics(dm); /* 窗口的宽度 */ screenWidth = dm.widthPixels; /* 窗口的高度 */ screenHeight = dm.heightPixels; // setTitle("宽"+screenWidth+" 高"+screenHeight); /* 设置为无标题栏 */ requestWindowFeature(Window.FEATURE_NO_TITLE); /* 设置为全屏模式 */ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); myView = new BallView(this); //设置显示GameSurfaceView视图 setContentView(myView); }//end of onCreate() //触笔事件 public boolean onTouchEvent(MotionEvent event) { return true; } //按键按下事件 public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { //菜单按键-设为初始菜单 case KeyEvent.KEYCODE_MENU: myView.resetGame(); //重新开始 break; //中间按键 case KeyEvent.KEYCODE_DPAD_CENTER: myView.ball_isRun = !myView.ball_isRun;//开始//暂停 break; //左方向键 case KeyEvent.KEYCODE_DPAD_LEFT: if(myView.ball_isRun){ if(myView.board_left<=myView.board_x_move) { myView.board_left=0; myView.board_right=myView.board_length; }else{ myView.board_left-=myView.board_x_move; myView.board_right-=myView.board_x_move;} } break; //右方向键 case KeyEvent.KEYCODE_DPAD_RIGHT: if(myView.ball_isRun){ if(screenWidth-myView.board_right<=myView.board_x_move ) { myView.board_left=screenWidth-myView.board_length; myView.board_right=screenWidth; }else{ myView.board_left+=myView.board_x_move; myView.board_right+=myView.board_x_move; } } break; //上方向键 case KeyEvent.KEYCODE_DPAD_UP: if(myView.ball_isRun){ if( myView.board_alterable_top==myView.board_default_top) { myView.board_alterable_top-=myView.boardYadd; myView.board_alterable_bottom-=myView.boardYadd; } } break; //下方向键 case KeyEvent.KEYCODE_DPAD_DOWN: if(myView.ball_isRun){ if( myView.board_alterable_top==myView.board_default_top-myView.boardYadd ) { myView.board_alterable_top=myView.board_default_top; myView.board_alterable_bottom=myView.board_alterable_top+myView.board_thickness; } } break; //返回键 case KeyEvent.KEYCODE_BACK: this.finish(); break; }//end switch return false; } //按键弹起事件 public boolean onKeyUp(int keyCode, KeyEvent event) { return true; } public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { return true; } } package ab.cc; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RadialGradient; import android.graphics.Shader; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; public class BallView extends SurfaceView implements SurfaceHolder.Callback, Runnable { //线程延时控制 final int ball_sleep=1;//毫秒,延时越大,球速越慢 final int ball_r= 8;//小球半径 final float ball2_r= 8;//底下滚珠小球半径 final int ballXorYadd = 4;//小球的基本位移。测试可行值:2,4 //获取屏幕宽度和高度 int screen_width;//320; int screen_height;//480; //砖的属性 int brick_width;//每块砖宽 int brick_height;//每块砖高 boolean brick_exist[];//砖是否存在 int k ;// 列//到for循环里才初始化 int j ;// 行 int brick_left = brick_width*(k-1);//到判断语句才初始化 int brick_right = brick_width*k; int brick_top = brick_height*j; int brick_bottom = brick_height*(j+1); //挡板的属性 int board_length;//挡板长度:80比较合适,可以随意修改,但别超过screen_width final int boardYadd = 16;//按上下键时挡板y方向位移量。经验证4、8、16可以,12不行 final int board_x_move = 30;//挡板x方向位移量:可以随意自定义 int board_left;//挡板左侧(可变) int board_right;//挡板右侧(可变) int board_thickness;//挡板厚度 int board_default_top;//即435,挡板的top面初始位置 int board_alterable_top;//挡板上侧(可变) int board_alterable_bottom;//挡板下侧(可变) int ball_default_x;//球的初始x坐标 int ball_default_y;//球的初始y坐标 //球的即时坐标(可变): int ball_x;//球心横坐标 int ball_y;//球心纵坐标 //球的前一步的y坐标 int ball_previous_y; int ball_x_speed;//球的横向偏移量//可变 int ball_y_speed;//球的纵向偏移量//可变 boolean ball_isRun;//球是否在动 // 控制循环 boolean mbLoop; // 定义SurfaceHolder对象 SurfaceHolder mSurfaceHolder = null; //获得分数 int score; /* 唤醒渐变渲染 */ Shader mRadialGradient = null; //------------------------------------------------------------------------------------------------------// public BallView(Context context) { super(context); // 实例化SurfaceHolder mSurfaceHolder = this.getHolder(); // 添加回调 mSurfaceHolder.addCallback(this); this.setFocusable(true); //获取屏幕宽度和高度 screen_width = BaomingActivity.screenWidth;//320 screen_height = BaomingActivity.screenHeight;//480 //砖的属性 brick_width = screen_width/5;//每块砖宽64 brick_height = screen_height/15;//每块砖高32 //挡板的属性 board_length = screen_width/4;//挡板长度:80比较合适,可以随意修改,但别超过screen_width board_left = (screen_width-board_length)/2;//挡板左侧(可变) board_right = (screen_width+board_length)/2;//挡板右侧(可变) board_thickness = 5;//挡板厚度 board_default_top = 13*screen_height/15;//即435,挡板的top面初始位置 board_alterable_top = board_default_top;//挡板上侧(可变) board_alterable_bottom = board_alterable_top+board_thickness;//挡板下侧(可变) ball_default_x = screen_width/2;//球的初始x坐标 ball_default_y = board_default_top - ball_r;//球的初始y坐标 //球的即时坐标(可变): ball_x = ball_default_x; ball_y = ball_default_y; //球的前一步的y坐标 ball_previous_y = 0; ball_x_speed = ballXorYadd;//球的横向偏移量 ball_y_speed = ballXorYadd;//球的纵向偏移量 mbLoop = true; ball_isRun = false; score=0; brick_exist = new boolean[25]; for (int i = 0; i < 25; i++) { brick_exist[i] = true; } /* 构建RadialGradient对象,设置半径的属性 */ mRadialGradient = new RadialGradient(ball_x, ball_y, ball_r,//球中心坐标x,y,半径r new int[]{Color.WHITE,Color.BLUE,Color.GREEN,Color.RED,Color.YELLOW},//颜色数组 null,//颜色数组中每一种颜色对应的相对位置,为空的话就是平均分布,由中心向外排布 Shader.TileMode.REPEAT);//渲染模式:重复 } public void resetGame(){ ball_isRun = false; score =0;//分数 ball_x_speed = ballXorYadd;//球的横向偏移量 ball_y_speed = ballXorYadd;//球的纵向偏移量 ball_x = screen_width/2;//球心起始横坐标 ball_y = board_default_top - ball_r;//球心起始纵坐标 board_left = (screen_width-board_length)/2;//挡板左侧 board_right = (screen_width+board_length)/2;//挡板右侧 board_alterable_top = board_default_top;//挡板上侧 board_alterable_bottom = board_alterable_top+board_thickness;//挡板下侧 for (int i = 0; i < 25; i++) { brick_exist[i] = true; } } //---------------------------------绘图循环开始---------------------------------- public void run() { while (mbLoop&&!Thread.currentThread().isInterrupted()) { try { Thread.sleep(ball_sleep); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } //球的前一步y坐标 ball_previous_y = ball_y; if (ball_isRun) { ballRunning();// 让小球移动 boardPositionCheck();//检测挡板是否处于“中线”位置,是就随小球上升一步,直至到“上线” hitWallCheck();//墙壁碰撞检测 hitBoardCheck();//挡板碰撞检测 hitBrickCheck();//砖块碰撞检测 } synchronized (mSurfaceHolder) { Draw(); } } } //---------------------------------绘图循环结束---------------------------------- //------------------------------------------------------------------------------ //让小球移动 public void ballRunning() { ball_x += ball_x_speed; ball_y -= ball_y_speed; } //朝左或朝右碰撞后小球水平方向逆向 public void ballLeftOrRightHit() { ball_x_speed *= -1; } //朝上或朝下碰撞后小球竖直方向逆向 public void ballUpOrDownHit() { ball_y_speed *= -1; } public void ballcornerHit() { ball_x_speed *= -1; ball_y_speed *= -1; } public void ballStraightUp() {//功能没实现,这是多余代码 ball_x_speed = 0;//注意在其他地方恢复 ball_y_speed *= -1; } //-------------------墙壁碰撞检测开始------------------------------------- public void hitWallCheck() { // 左碰墙 if (ball_x <= ball_r && ball_y >= ball_r && ball_y <= screen_height) { ballLeftOrRightHit(); // 右碰墙 } if (ball_x >= screen_width - ball_r && //不能写为 else if,因为可能恰好碰到角落。 ball_y >= ball_r && ball_y <= screen_height) { ballLeftOrRightHit(); } // 上碰墙 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && ball_y <= ball_r + brick_height) //、、、、、、、、、、、、、、、25号修改 { ballUpOrDownHit(); } // 下碰墙 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && ball_y >= screen_height-ball_r) { ballUpOrDownHit(); if(score<=10){ score = 0; } else score-=10; } } //-------------------墙壁碰撞检测结束------------------------------------- //-----------------------------挡板碰撞检测开始--------------------------- public void hitBoardCheck() { // 下碰挡板正面 if (ball_x >= ball_r && ball_x <= screen_width - ball_r && //在屏幕内,起码条件 ball_x >= board_left && ball_x <= board_right && //在挡板X域上方 ball_y == board_alterable_top - ball_r &&//球面与挡板相切 ball_previous_y <= board_alterable_top - ball_r //确定球是从上方下落 ) { if(board_alterable_top==board_default_top-boardYadd ){//如果弹簧伸张,挡板位于上线 ballHitBoardlower();//作用:ball_y_move减小;挡板被打下;小球Y向运动反向 } else if(board_alterable_top==board_default_top){//如果弹簧压缩,挡板位于下线 boardHitBallHigher();//作用:ball_y_move增加;挡板弹上;小球Y向运动反向 } } //斜碰挡板右上角//经验证有效 else if(Math.pow(board_right-ball_x, 2)+Math.pow(board_alterable_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>board_right && ball_y<board_alterable_top) { ballcornerHit(); } //斜碰挡板的左上角//经验证有效 else if(Math.pow(board_left-ball_x, 2)+Math.pow(board_alterable_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x<board_left && ball_y<board_alterable_top) { ballcornerHit(); } } //-----------------------------挡板碰撞检测结束-------------------------- private void boardHitBallHigher() {//增强 ballUpOrDownHit();//小球Y方向反向,ball_y_speed变为正数 if(ball_y_speed == ballXorYadd ){ ball_y_speed += ballXorYadd;//离开挡板后小球Y方向速度增强 } if( boardYadd > ball_y_speed ){//在线程这一轮,小球上升多少,挡板就上升多少。 board_alterable_top = board_default_top - ball_y_speed; board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } } //检测挡板是否处于“中线”位置,是就随小球上升一步,直至到“上线” private void boardPositionCheck() {//还可直接利用球的位置刷新,board_top与球心相差ball_r if(board_alterable_top < board_default_top && board_alterable_top > board_default_top-boardYadd){ //挡板随球上升 if(board_alterable_top - ball_y_speed >= board_default_top-boardYadd){ board_alterable_top -= ball_y_speed;//挡板上层面 board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } else{ board_alterable_top = board_default_top-boardYadd;//挡板上层面 board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面 } } } private void ballHitBoardlower() {//减弱 board_alterable_top=board_default_top; board_alterable_bottom=board_default_top+board_thickness;//挡板被打退 ballUpOrDownHit();//小球Y方向反向 if(ball_y_speed==2*ballXorYadd){ ball_y_speed -= ballXorYadd;//小球Y方向速度减弱 } } //砖块碰撞检测开始----------------------------------------------------------- public void hitBrickCheck() { for (int i = 0; i <25 ; i++) { if (brick_exist[i]) { k = i % 5+1;// 1,2,3,4,5循环 j = i / 5+1;// 1,1,1,1,1;2,2,2,2,2,;...;5,5,5,5,5 brick_left = brick_width*(k-1); brick_right = brick_width*k; brick_top = brick_height*j; brick_bottom = brick_height*(j+1); //朝下碰砖的top面 AAAAAAAAAAAAAAAAAAAAA if(ball_x >= brick_left && ball_x <= brick_right && ball_y >= brick_top-ball_r && ball_y < brick_top) { ballUpOrDownHit(); brick_exist[i] = false; score+=4; //朝下正碰2砖中间,i砖右上角检测 if(k!=5 && ball_x == brick_right)//如果不是第5列砖的右侧边 { //如果砖[i+1]存在 if(brick_exist[i+1]){ brick_exist[i+1] = false; score+=4; } } //朝下正碰2砖中间,i砖左上角检测 else if(k!=1 && ball_x == brick_left)//如果不是第1列砖的左侧边 { //如果砖[i-1]存在 if(brick_exist[i-1]){ brick_exist[i-1] = false; score+=4; } } } //朝上碰砖的bottom面 BBBBBBBBBBBBBBBBB else if(ball_x >= brick_left && ball_x <= brick_right && ball_y > brick_bottom&& ball_y <= brick_bottom + ball_r ) { ballUpOrDownHit(); brick_exist[i] = false; score+=4; //朝上正碰2块砖中间--i砖的右下角检测 if(k!=5 && ball_x == brick_right) //如果不是第5列砖的右侧边 { if(brick_exist[i+1]){//如果砖[i+1]存在 brick_exist[i+1] = false; score+=4; } } //朝上正碰2块砖中间--i砖的左下角检测 else if(k!=1 && ball_x == brick_left) //如果不是第1列砖的左侧边 { if(brick_exist[i-1]){//如果砖[i-1]存在 brick_exist[i-1] = false; score+=4; } } } //朝右碰砖的left面CCCCCCCCCCCCCCCCC else if(ball_x >= brick_left -ball_r&&ball_x < brick_left&& ball_y >= brick_top && ball_y <= brick_bottom) { ballLeftOrRightHit(); brick_exist[i] = false; score+=4; //朝右正碰2块砖中间,左下角检测 if(j!=5 && ball_y == brick_bottom)//如果不是第5行砖的下侧边 { if(brick_exist[i+5]){//如果砖[i+5]存在 brick_exist[i+5] = false; score+=4; } } //朝右正碰2块砖中间,左上角检测 else if(j!=1 && ball_y == brick_top)//如果不是第1行砖的上侧边 { if(brick_exist[i-5]){//如果砖[i-5]存在 brick_exist[i-5] = false; score+=4; } } } //朝左碰砖的right面DDDDDDDDDDDDDDDDDD else if(ball_x >= brick_right && ball_x <= brick_right+ball_r&& ball_y >= brick_top && ball_y <= brick_bottom) { ballLeftOrRightHit(); brick_exist[i] = false; score+=4; //朝左正碰2块砖中间,右下角检测 if(j!=5 && ball_y == brick_bottom )//如果不是第5行砖的下侧边 { if(brick_exist[i+5]){//如果砖[i+5]存在 brick_exist[i+5] = false; score+=4; } } //朝左正碰2块砖中间,右上角检测 else if(j!=1 && ball_y == brick_top )//如果不是第1行砖上侧边 { if(brick_exist[i-5]){//如果砖[i-5]存在 brick_exist[i-5] = false; score+=4; } } } ///////////////////////////////////////// //斜碰i砖的左下角EEEEEEEEEEEEEEEEEEEEEEEE else if(( i-1<0||(i-1>=0&&!brick_exist[i-1]) ) && (i+5>=25||(i+5<25&&!brick_exist[i+5]) )&& Math.pow(brick_left-ball_x, 2)+Math.pow(brick_bottom-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_left-ball_r && ball_x<brick_left && ball_y>brick_bottom && ball_y<brick_bottom+ball_r ) { ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的右下角FFFFFFFFFFFFFFFFFFFFFFFFFF else if( (i+1>=25||(i+1<25&&!brick_exist[i+1]) )&& (i+5>=25||(i+5<25&&!brick_exist[i+5]) )&& Math.pow(brick_right-ball_x, 2)+Math.pow(brick_bottom-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_right&&ball_x<brick_right+ball_r&& ball_y>brick_bottom&&ball_y<brick_bottom+ball_r ) { Log.v("----------", "right bottom hit"+i+":"+brick_exist[i]); ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的右上角GGGGGGGGGGGGGGGGGGGGGGGG else if( (i+1>=25||(i+1<25&&!brick_exist[i+1]) )&& (i-5<0||(i-5>0&&!brick_exist[i-5]) )&& Math.pow(brick_right-ball_x, 2)+Math.pow(brick_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_right && ball_x<brick_right+ball_r&& ball_y>brick_top-ball_r && ball_y<brick_top) { ballcornerHit(); brick_exist[i] = false; score+=4; } //斜碰i砖的左上角HHHHHHHHHHHHHHHHHHHHHHHHHH else if((i-1<0||(i-1>=0&&!brick_exist[i-1])) && (i-5<0||(i-5>=0&&!brick_exist[i-5])) && Math.pow(brick_left-ball_x, 2)+Math.pow(brick_top-ball_y,2)<=Math.pow(ball_r, 2)&& ball_x>brick_left-ball_x && ball_x<brick_left && ball_y>brick_top-ball_r && ball_y<brick_top ) { ballcornerHit(); brick_exist[i] = false; score+=4; } }//end if }//end for }//end hitBrickCheck() //砖块碰撞检测结束----------------------------------------------------------- //------------------------------------------ public boolean gameOver(){ int count = 0; for(boolean s:brick_exist){ if(!s){ count++; } } if(count == 25){ return true; }else{ return false; } } //------------------------------------------ //---------------绘图方法开始------------------------ public void Draw() { // 锁定画布,得到canvas Canvas canvas = mSurfaceHolder.lockCanvas(); if (mSurfaceHolder == null || canvas == null) { return; } // 绘图 Paint mPaint = new Paint(); // 设置取消锯齿效果 mPaint.setAntiAlias(true); mPaint.setColor(Color.BLACK); // 绘制矩形--背景 canvas.drawRect(0, 0, screen_width, brick_height-2, mPaint); mPaint.setColor(Color.GREEN); // 绘制矩形--背景 canvas.drawRect(0, brick_height-2, screen_width, screen_height, mPaint); mPaint.setColor(Color.RED);//设置字体颜色 mPaint.setTextSize(brick_height-7);//设置字体大小 canvas.drawText("得分:"+score, 0, brick_height-7, mPaint); // 绘制顶层挡板````````````````````````````````````````````````````````25号修改 mPaint.setColor(Color.BLACK);//设置颜色 mPaint.setStrokeWidth(4);//设置粗细 canvas.drawLine(0, brick_height-2, screen_width, brick_height-2, mPaint); for (int i = 0; i <25 ; i++) { if (brick_exist[i]) { k = i % 5+1;// 1,2,3,4,5循环 j = i / 5+1;// 1,1,1,1,1;2,2,2,2,2,;...;5,5,5,5,5 brick_left = brick_width*(k-1); brick_right = brick_width*k; brick_top = brick_height*j; brick_bottom = brick_height*(j+1); mPaint.setStyle(Paint.Style.FILL);// 设置实心画笔 mPaint.setColor(Color.YELLOW); canvas.drawRect(brick_left+1, brick_top+1, brick_right-1,brick_bottom-1, mPaint); mPaint.setStyle(Paint.Style.STROKE);// 设置空心画笔 mPaint.setStrokeWidth(2);//设置粗细 mPaint.setColor(Color.BLUE); canvas.drawRect(brick_left+3, brick_top+3, brick_right-3,brick_bottom-3, mPaint); } } // 设置实心画笔 mPaint.setStyle(Paint.Style.FILL); { mPaint.setShader(mRadialGradient); canvas.drawCircle(ball_x, ball_y, ball_r, mPaint); } Paint mPaint2 = new Paint(); // 设置取消锯齿效果 mPaint2.setAntiAlias(true); // 设置实心画笔 mPaint2.setStyle(Paint.Style.FILL); { mPaint2.setColor(Color.BLACK); /* 绘制矩形挡板 */ canvas.drawRect(board_left, board_alterable_top, board_right, board_alterable_bottom,mPaint2); float board2_bottom = screen_height - 2*ball2_r;//164 float board2_top = board2_bottom - 4;//160 //线段端点坐标数组 float x0 = board_left+(board_right-board_left)/4; float y0 = board_alterable_bottom;//440或者444 float springAdd = (board2_top- board_alterable_bottom)/8;//即2.5或者2:弹簧小线段的y向长度 float springWidth = 5.0f;//弹簧小线段的x向长度 float x1 = x0 - springWidth; float y1 = y0 + springAdd; float x2 = x0 + springWidth; float y2 = y0 + 3*springAdd; float x3 = x1 ; float y3 = y0 + 5*springAdd; float x4 = x2; float y4 = y0 + 7*springAdd; float x5 = x0 ; float y5 = board2_top;//即460 float between_spring = (board_right-board_left)/2; float pts[] = { x0,y0,x1,y1, x1,y1,x2,y2, x2,y2,x3,y3, x3,y3,x4,y4, x4,y4,x5,y5}; float pts2[] = {x0+between_spring,y0, x1+between_spring,y1, x1+between_spring,y1, x2+between_spring,y2, x2+between_spring,y2, x3+between_spring,y3, x3+between_spring,y3, x4+between_spring,y4, x4+between_spring,y4, x5+between_spring,y5}; mPaint2.setStrokeWidth(2);//设置弹簧粗细 //绘制2个弹簧 canvas.drawLines(pts, mPaint2); canvas.drawLines(pts2, mPaint2); //绘制下层挡板 canvas.drawRect(board_left, board2_top, board_right, board2_bottom,mPaint2); mPaint2.setColor(Color.BLACK);// // 绘制最下面的两个“轮子”(圆心x,圆心y,半径r,p) canvas.drawCircle(board_left+ball2_r, screen_height-ball2_r, ball2_r, mPaint2);//圆 canvas.drawCircle(board_right-ball2_r, screen_height-ball2_r, ball2_r, mPaint2); mPaint2.setColor(Color.WHITE);// canvas.drawPoint(board_left+ball2_r, screen_height-ball2_r, mPaint2);//绘制左轮轮心 canvas.drawPoint(board_right-ball2_r, screen_height-ball2_r, mPaint2);//绘制右轮轮心 }//实心画笔mPaint2结束 if(gameOver()){ // mbLoop = false;//注释掉的话GAME OVER后也可重启 ball_isRun = false; mPaint2.setColor(Color.BLACK);//设置字体颜色 mPaint2.setTextSize(40.0f);//设置字体大小 canvas.drawText("GAME OVER", screen_width/32+40, screen_height/16*9-70, mPaint2); mPaint2.setTextSize(20.0f);//设置字体大小 canvas.drawText("Press \"MENU\" button to restart,", screen_width/32, //320/32=10 screen_height/16*9, //480/16=30,30*9=270 mPaint2); canvas.drawText("Press \"BACK\" button to exit.", screen_width/32, //320/32=10 screen_height/16*10, //480/16=30,30*10=300 mPaint2); } // 绘制后解锁,绘制后必须解锁才能显示 mSurfaceHolder.unlockCanvasAndPost(canvas); }// end of Draw() //---------------------绘图方法结束----------------------------------------------- // 在surface的大小发生改变时激发 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } // 在surface创建时激发 public void surfaceCreated(SurfaceHolder holder) { new Thread(this).start();// 开启绘图线程 } // 在surface销毁时激发 public void surfaceDestroyed(SurfaceHolder holder) { // 停止循环 mbLoop = false; } } package sen.tan; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; public class dazhuankuaiActivity extends Activity { BallView myview; public static int screenWidth ; public static int screenHeight; private TextView textview; Button kaishi,jieshu,guanyu; ImageView image; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String string = "欢迎进入疯狂打砖块游戏"; image = (ImageView) this.findViewById(R.id.image); image.setImageResource(R.drawable.img1); textview =(TextView) this.findViewById(R.id.textview); textview.setTextSize(20); textview.setTextColor(Color.GREEN); textview.setBackgroundColor(Color.RED); textview.setText(string); kaishi=(Button)findViewById(R.id.button1); guanyu=(Button)findViewById(R.id.button2); jieshu=(Button)findViewById(R.id.button3); kaishi.setWidth(250); guanyu.setWidth(200); jieshu.setWidth(150); kaishi.setTextSize(35); guanyu.setTextSize(29); jieshu.setTextSize(24); jieshu.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v) { dazhuankuaiActivity.this.finish(); } }); guanyu.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ textview.setText("本游戏由邵明森和谭明星制作,此游戏控制左右按键,来回移动挡板,不让小球掉落,当小球把上方砖块全部打完时,游戏胜利"); } }); kaishi.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ public void onCreate(Bundle savedInstanceState)这里显示的错误 显示的是上面两个括号标示不对。 { super.onCreate(savedInstanceState); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels; screenHeight = dm.heightPixels; setTitle("宽"+screenWidth+" 高"+screenHeight); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); myview = new BallView(this); setContentView(myview); } } public boolean onTouchEvent(MotionEvent event) { return true; } public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_MENU: myview.resetGame(); break; case KeyEvent.KEYCODE_DPAD_CENTER: myview.ball_isRun = !myview.ball_isRun; break; case KeyEvent.KEYCODE_DPAD_LEFT: if(myview.ball_isRun){ if(myview.board_left<=myview.board_x_move) { myview.board_left=0; myview.board_right=myview.board_length; }else{ myview.board_left-=myview.board_x_move; myview.board_right-=myview.board_x_move;} } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if(myview.ball_isRun){ if(screenWidth-myview.board_right<=myview.board_x_move ) { myview.board_left=screenWidth-myview.board_length; myview.board_right=screenWidth; }else{ myview.board_left+=myview.board_x_move; myview.board_right+=myview.board_x_move; } } break; case KeyEvent.KEYCODE_DPAD_UP: if(myview.ball_isRun){ if( myview.board_alterable_top==myview.board_default_top) { myview.board_alterable_top-=myview.boardYadd; myview.board_alterable_bottom-=myview.boardYadd; } } break; case KeyEvent.KEYCODE_DPAD_DOWN: if(myview.ball_isRun){ if( myview.board_alterable_top==myview.board_default_top-myview.boardYadd ) { myview.board_alterable_top=myview.board_default_top; myview.board_alterable_bottom=myview.board_alterable_top+myview.board_thickness; } } break; case KeyEvent.KEYCODE_BACK: this.finish(); break; } return false; } public boolean onKeyUp(int keyCode, KeyEvent event) { return true; } public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { return true; } } ); } }

安卓内怎样使AlertDialog消失

新建了一个AlertDialog,代码如下 LinearLayout new_operation = (LinearLayout) getLayoutInflater().inflate(R.layout.contact_check_contact_dialog1,null); final Button Edit = (Button) new_operation.findViewById(R.id.check_contact_edit); final Button Delete = (Button) new_operation.findViewById(R.id.check_contact_delete); new AlertDialog.Builder(Check_contact.this) .setTitle("请选择操作") .setView(new_operation) .create() .show(); Delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { list1.remove(position); ListAdapter adapter = new SimpleAdapter(getBaseContext(),list1,R.layout.contact_viewhold,new String[]{"groupName","userCount"},new int[]{R.id.contact_viewhold_groupName,R.id.contact_viewhold_userCount}); contact.setAdapter(adapter);} 我是绑定一个自定义的视图文件,在试图文件中定义了两个按键,但是点击按键后发现对话框没有消失,该用什么语句让它消失?我试了dismiss,但是只有dismissDialog(int id)这个选项,如果用这个的话,那个id值该是多少? 我引用的是android.support.v7.app.AlertDialog这个包

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

Linux 会成为主流桌面操作系统吗?

整理 |屠敏出品 | CSDN(ID:CSDNnews)2020 年 1 月 14 日,微软正式停止了 Windows 7 系统的扩展支持,这意味着服役十年的 Windows 7,属于...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

学习总结之HTML5剑指前端(建议收藏,图文并茂)

前言学习《HTML5与CSS3权威指南》这本书很不错,学完之后我颇有感触,觉得web的世界开明了许多。这本书是需要有一定基础的web前端开发工程师。这本书主要学习HTML5和css3,看...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

搜狗输入法也在挑战国人的智商!

故事总是一个接着一个到来...上周写完《鲁大师已经彻底沦为一款垃圾流氓软件!》这篇文章之后,鲁大师的市场工作人员就找到了我,希望把这篇文章删除掉。经过一番沟通我先把这篇文章从公号中删除了...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

新一代神器STM32CubeMonitor介绍、下载、安装和使用教程

关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang最近ST官网悄悄新上线了一款比较强大的工具:STM32CubeMonitor V1.0.0。经过我研究和使用之...

记一次腾讯面试,我挂在了最熟悉不过的队列上……

腾讯后台面试,面试官问:如何自己实现队列?

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

冒泡排序动画(基于python pygame实现)

本项目效果初始截图如下 动画见本人b站投稿:https://www.bilibili.com/video/av95491382 本项目对应github地址:https://github.com/BigShuang python版本:3.6,pygame版本:1.9.3。(python版本一致应该就没什么问题) 样例gif如下 ======================= 大爽歌作,mad

Redis核心原理与应用实践

Redis核心原理与应用实践 在很多场景下都会使用Redis,但是到了深层次的时候就了解的不是那么深刻,以至于在面试的时候经常会遇到卡壳的现象,学习知识要做到系统和深入,不要把Redis想象的过于复杂,和Mysql一样,是个读取数据的软件。 有一个理解是Redis是key value缓存服务器,更多的优点在于对value的操作更加丰富。 安装 yum install redis #yum安装 b...

现代的 “Hello, World”,可不仅仅是几行代码而已

作者 |Charles R. Martin译者 | 弯月,责编 | 夕颜头图 |付费下载自视觉中国出品 | CSDN(ID:CSDNnews)新手...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

!大部分程序员只会写3年代码

如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

HTTP与HTTPS的区别

面试官问HTTP与HTTPS的区别,我这样回答让他竖起大拇指!

程序员毕业去大公司好还是小公司好?

虽然大公司并不是人人都能进,但我仍建议还未毕业的同学,尽力地通过校招向大公司挤,但凡挤进去,你这一生会容易很多。 大公司哪里好?没能进大公司怎么办?答案都在这里了,记得帮我点赞哦。 目录: 技术氛围 内部晋升与跳槽 啥也没学会,公司倒闭了? 不同的人脉圈,注定会有不同的结果 没能去大厂怎么办? 一、技术氛围 纵观整个程序员技术领域,哪个在行业有所名气的大牛,不是在大厂? 而且众所...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

立即提问
相关内容推荐