Activity横屏和竖屏切换问题:

xiaoleelee 2011-08-08 11:57:40
我有一个工程,启动一个Activity,在这个Activity中又启动了一个新的Activity,当在这个新的Activity中执行竖屏操作后,返回到手机桌面,在新的Activity中执行横屏操作时,返回的是启动它的Activity.
我想要的是,不管在横屏或是竖屏下操作,都会返回到手机桌面。请高手赐教!
另:manifest.xml文件中有关方向的设置已经设置正确!
...全文
146 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wodejiang2009 2011-08-08
  • 打赏
  • 举报
回复
跳转之前的时候finish吧。
六百万 2011-08-08
  • 打赏
  • 举报
回复
不管3,7,21,只要在新的activity中点击返回键就finish
dinjay 2011-08-08
  • 打赏
  • 举报
回复
在你的新的activity中对横竖屏切换做处理,如果是竖屏,就直接finish这个activity。
android调用camera时,可以自己写一个activity,赋上相关参数,打开前camera就可以了; 需要申请的permission,在AndroidManifest.xml中添加: 主要功能,打开前camera private Camera openFrontFacingCameraGingerbread() { int cameraCount = 0; Camera cam = null; Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraCount = Camera.getNumberOfCameras(); for (int camIdx = 0; camIdx < cameraCount; camIdx++) { Camera.getCameraInfo(camIdx, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { try { cam = Camera.open(camIdx); mCurrentCamIndex = camIdx; } catch (RuntimeException e) { Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage()); } } } return cam; } 根据打开时的横竖屏方向来调整preview角度 //根据横竖屏自动调节preview方向,Starting from API level 14, this method can be called when preview is active. private static void setCameraDisplayOrientation(Activity activity,int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); //degrees the angle that the picture will be rotated clockwise. Valid values are 0, 90, 180, and 270. //The starting position is 0 (landscape). int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); }

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧