在<Activity>中加入这一行android:screenOrientation="landscape/portrait ",android中每次屏幕的切换动会重启Activity ,不过如果使用android:configChanges="keyboardHidden|orientation",当我们横竖屏切换的时候会直接调用onCreate方法中的onConfigurationChanged方法,而不会重新执行onCreate方法,那当然如果不配置这个属性的话就会重新调用onCreate方法了
1.放大缩放图片大小 Bitmap bitmap=null; bitmap=BitmapFactory.decodeResource(getResources(),resourcesID); int bitWidth=bitmap.getWidth(); int bitHeight=bitmap.getHeight(); float scaleWidth=src_width/(float)bitWidth;(src_width可以是桌面宽度) float scaleHeight=src_height/(float)bitHight; Matrix matrix=new Matrix(); matrix.postScale(scaleWidth,scaleHeight); bitMap=Bitmap.createBitmap(bitmap,0,0,bitWidth,bitHeight,Matrix,true)
在surfaceView初始化函数的时候不要对ScreenW和ScreenH进行赋值,如果你在初始化调用ScreenW = this.getWidth();和ScreenH = this.getHeight();得到的值全部为0,只有SurfaceCreated()执行的时候,真正的view才会被建立
mCanvas = mHolder.lockCanvas(); mCanvas.drawRect(0, 0, mScreenWidth, mScreenHeight, mPaint1); mCanvas.save(); mCanvas.drawText("xlm", initX + 2, initY - 5, mPaint2); /** * mCanvas.clipRect * 是为了抠出一个小人出来,放mCanvas.drawBitmap中的图片,同时mCanvas.drawBitmap为什么要initX - * animation_image[frameCount] bitmap.getWidth() / 4, initY - 3 * * bitmap.getHeight() / 4 捏?其根本原因就是为了将bitmap左移上移,来显示出bitmap这一大张图片中的每张小图 */ mCanvas.clipRect(initX, initY, initX + bitmap.getWidth() / 4, initY + bitmap.getHeight() / 4); if (up) { mCanvas.drawBitmap(bitmap, initX - animation_image[frameCount] * bitmap.getWidth() / 4, initY - 3 * bitmap.getHeight() / 4, mPaint1); } else if (down) { mCanvas.drawBitmap(bitmap, initX - animation_image[frameCount] * bitmap.getWidth() / 4, initY, mPaint1); } else if (left) { mCanvas.drawBitmap(bitmap, initX - animation_image[frameCount] * bitmap.getWidth() / 4, initY - 1 * bitmap.getHeight() / 4, mPaint1); } else if (right) { mCanvas.drawBitmap(bitmap, initX - animation_image[frameCount] * bitmap.getWidth() / 4, initY - 2 * bitmap.getHeight() / 4, mPaint1); } mCanvas.restore(); mHolder.unlockCanvasAndPost(mCanvas);