分享

Unity横屏切换导致宽高不正确Android 屏幕横竖问题

 tiancaiwrk 2015-10-16
// -------------------------------- Android 屏幕横竖问题
private int width,height;
// Setup activity layout
@Override protected void onCreate (Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
 
getWindow().takeSurface(null);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFormat(PixelFormat.RGB_565);
 
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
                      WindowManager.LayoutParams.FLAG_FULLSCREEN);
 
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
//保存一下游戏屏幕的宽和高
DisplayMetrics dm = getResources().getDisplayMetrics();
width = dm.widthPixels;
height = dm.heightPixels;
}
// This ensures the layout will be correct.
@Override public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
//在这里强制设置一下屏幕的宽和高
mUnityPlayer.getView().getLayoutParams().width = width;
mUnityPlayer.getView().getLayoutParams().height = height;
Log.v("unity", width+" " + height );
mUnityPlayer.configurationChanged(newConfig);
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多