PrevIEwSurface.java:-
public class PrevIEwSurface extends SurfaceVIEw implementsSurfaceHolder.Callback { public static final String LOG_TAG = "CameraPrevIEw"; private SurfaceHolder mSurfaceHolder; private Camera mCamera; // Constructor that obtains context and camera @SuppressWarnings("deprecation") public PrevIEwSurface(Context context,Camera camera) { super(context); this.mCamera = camera; this.mSurfaceHolder = this.getHolder(); this.mSurfaceHolder.addCallback(this); this.mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); this.mSurfaceHolder.setFixedSize(100,100); } @OverrIDe public voID surfaceCreated(SurfaceHolder surfaceHolder) { try { Camera.Parameters parameters = mCamera.getParameters(); if (this.getResources().getConfiguration().orIEntation != Configuration.ORIENTATION_LANDSCAPE) { parameters.set("orIEntation","portrait"); mCamera.setdisplayOrIEntation(90); parameters.setRotation(90); mCamera.setPrevIEwdisplay(surfaceHolder); mCamera.startPrevIEw(); } else { // This is an undocumented although wIDely kNown feature parameters.set("orIEntation","landscape"); // For AndroID 2.2 and above mCamera.setdisplayOrIEntation(0); // Uncomment for AndroID 2.0 and above parameters.setRotation(0); } mCamera.setPrevIEwdisplay(surfaceHolder); mCamera.startPrevIEw(); } catch (IOException e) { // left blank for Now } } @OverrIDe public voID surfaceDestroyed(SurfaceHolder surfaceHolder) { mCamera.stopPrevIEw(); mCamera.release(); } @OverrIDe public voID surfaceChanged(SurfaceHolder surfaceHolder,int format,int wIDth,int height) { try { Camera.Parameters parameters = mCamera.getParameters(); if (this.getResources().getConfiguration().orIEntation != Configuration.ORIENTATION_LANDSCAPE) { parameters.set("orIEntation","portrait"); mCamera.setdisplayOrIEntation(90); parameters.setRotation(90); } else { // This is an undocumented although wIDely kNown feature parameters.set("orIEntation","landscape"); // For AndroID 2.2 and above mCamera.setdisplayOrIEntation(0); // Uncomment for AndroID 2.0 and above parameters.setRotation(0); } mCamera.setPrevIEwdisplay(surfaceHolder); mCamera.startPrevIEw(); } catch (IOException e) { // left blank for Now } }}
我可以知道我在哪里做错了,我在代码中错过了什么?
解决方法 您必须处理应用程序的配置更改.将此行添加到AndroIDManifest.xml.
androID:configChanges="keyboardHIDden|orIEntation|screenSize"
This tells the system what configuration changes you are going to handle yourself – in this case by doing nothing.
希望它有助于ツ
总结以上是内存溢出为你收集整理的android – 禁用方向更改全部内容,希望文章能够帮你解决android – 禁用方向更改所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)