切换全屏和放大器;定向像YouTube [英] Toggling fullscreen & orientation like YouTube

查看:161
本文介绍了切换全屏和放大器;定向像YouTube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图模仿Android版YouTube应用的行为被点击视频播放器的全屏按钮时:

I am trying to mimic the behavior of the YouTube Android app when the "fullscreen" button is clicked in the video player:


  • 如果设备是目前在肖像,马上旋转为横向(即使用户仍持纵向装置),并留在景观,直到用户旋转设备到横向,然后旋转回纵向

    • 如果设备目前在景观,马上旋转为纵向(即使用户仍持纵向装置),并留在肖像,直到用户旋转设备肖像,然后转回到风景线。

    • 在任何时间,允许用户手动旋转他们的设备到所需方向。

    看来,如果我强迫旋转到横向或纵向使用:

    It seems that if I force the rotation to landscape or portrait using:

    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    

    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    ...我立即失去检测传感器定位变化的能力(即当用户在景观,他们要手动旋转装置回人像)。

    ... I immediately lose the ability to detect sensor orientation changes (i.e. once the user is in landscape, and they want to manually rotate the device back to portrait).

    如果我更改请求的方向在onConfigurationChanged未指定或传感器,定向简单翻转到横向/纵向(无论我从上面的要求),然后弹回匹配设备如何保持方向。

    If I change the requested orientation to unspecified or sensor in onConfigurationChanged, the orientation briefly flips to landscape/portrait (whatever I requested from above) and then snaps back to the orientation that matches how the device is held.

    这是如何实现以上?我的目标有什么想法

    Any thoughts on how to achieve my goals above?

    推荐答案

    我有excact同样的问题。我最终什么了,用一个OrientationListener检测,当用户实际上倾斜手机横向的,然后设置定向SCREEN_ORIENTATION_SENSOR。

    I had the excact same problem. What I ended up with was using an OrientationListener to detect when the user had actually tilted the phone to landscape and then setting the orientation to SCREEN_ORIENTATION_SENSOR.

    OrientationEventListener orientationEventListener = 
    new OrientationEventListener(getActivity()) {
        @Override
        public void onOrientationChanged(int orientation) {
            int epsilon = 10;
            int leftLandscape = 90;
            int rightLandscape = 270;
            if(epsilonCheck(orientation, leftLandscape, epsilon) ||
               epsilonCheck(orientation, rightLandscape, epsilon)){
                    getMainActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
                }
            }
    
            private boolean epsilonCheck(int a, int b, int epsilon) {
                return a > b - epsilon && a < b + epsilon;
            }
        };
        orientationEventListener.enable();
    

    下面是OrientationEventListener的文档:<一href=\"http://developer.android.com/reference/android/view/OrientationEventListener.html#onOrientationChanged%28int%29\"相对=nofollow>文档

    Here is the documentation for OrientationEventListener : Documentation

    您还需要添加检查画像,因为你需要描述在你原来的职位。

    You would also need to add checks for portrait , because you described needing that in your original post.

    这篇关于切换全屏和放大器;定向像YouTube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆