控件(播放器)全屏和半屏切换

来源:互联网 发布:ubuntu安装后分区 编辑:程序博客网 时间:2024/05/21 09:54

        /** *设置全屏 */public void setupFullScreen(){        WindowManager.LayoutParams attrs = getWindow().getAttributes();        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);        attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;        getWindow().setAttributes(attrs);        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);        //获取屏幕尺寸        WindowManager manager = this.getWindowManager();        DisplayMetrics metrics = new DisplayMetrics();        manager.getDefaultDisplay().getMetrics(metrics);        //设置Video布局尺寸        mVideoLayout.getLayoutParams().width = metrics.widthPixels;        mVideoLayout.getLayoutParams().height = metrics.heightPixels;        mIsFullScreen = true;}/** * no全屏 */private void setupUnFullScreen() {        WindowManager.LayoutParams attrs = getWindow().getAttributes();        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);        attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);        getWindow().setAttributes(attrs);        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);        float width = getResources().getDisplayMetrics().heightPixels;        float height = dp2px(200.f);        mVideoLayout.getLayoutParams().width = (int) width;        mVideoLayout.getLayoutParams().height = (int) height;        //设置为全屏        mIsFullScreen = false;    }

最近公司在开发vr播放器,做到播放器点击右下角全屏半屏切换时遇到问题,就查了些资料整理了哈 送个需要的人



0 0