项目需求:登录、大厅界面、部分小游戏均为横屏,有一款游戏需要竖屏显示。
现在已经在安卓上实现屏幕旋转,但是旋转后仍然是横屏的分辨率显示,在屏幕上只显示了横屏时的高度的内容。
我对java代码只会搬砖,希望能贴上代码。
提前感谢
这是我把屏幕旋转后的样子,只显示了一半;
旋转屏幕的代码相关:
java代码:
public static void changedActivityOrientation( int orientation){
– m_Orientation = orientation;
– switch(orientation){
---- case 1: // 横屏
------ instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
------ break;
---- case 2: // 竖屏
------ instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
------ break;
---- }
}
lua代码:
if device.platform == “android” then
– local luaj = require “cocos.cocos2d.luaj”
– local ok,ret = luaj.callStaticMethod(“com/htkj/wryl/AppActivity”, “changedActivityOrientation”,{2},"(I)V")
---- if not ok then
------ print(“luaj error:” … tostring(ret))
---- else
------ print(“The ret is:” … tostring(ret))
---- end
– end
– local frameSize = cc.Director:getInstance():getOpenGLView():getFrameSize()
– if frameSize.height < frameSize.width then
---- cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(frameSize.height, frameSize.width, cc.ResolutionPolicy.FIXED_WIDTH)
---- cc.Director:getInstance():getOpenGLView():setFrameSize(frameSize.height, frameSize.width)
– end