视频不重新调整大小时改变方向 [英] Video doesn't re-size when orientation changes

查看:225
本文介绍了视频不重新调整大小时改变方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段使用SurfaceView的视频显示。如果我改变屏幕的方向,而播放视频时不会调整。例如,如果视频是横向尺寸(全屏幕)播放,它不会当屏幕旋转到纵向尺寸。它仍然景观如果大小。如果我开始在风景视频,也不会改变portrait.I用我的清单如下:

I have a video displayed using SurfaceView in a fragment. If I change the orientation of the screen while the video is playing it doesn't resize. For example, if the video is playing in landscape size (full screen), it doesn't go to portrait size when the screen is rotated. It remains if landscape size. If I start the video in landscape, it won't change to portrait.I am using the following in my manifest:

    <activity
        android:name=".BassActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        >

我有这个在我的的onCreate

I have this in my "onCreate"

 @Override
 public void onCreate(Bundle savedInstanceState) {
   if (VERBOSE) Log.v(TAG, "+++ onCreate +++");
     super.onCreate(savedInstanceState);        
     getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
     setRetainInstance(true);

我想为视频,从纵向到横向,当我旋转屏幕重新大小,例如,在播放时。

I would like for the video to re-size, for example from portrait to landscape when I rotate the screen, while it is playing.

我还添加了一个敬酒消息 onSurfaceChanged 看到它被触发时,但是当我旋转屏幕是不会触发。我怎样才能重新大小的视频已开始播放后?

I also added a toast message to onSurfaceChanged to see when it is triggered,but it is not trigger when I rotate the screen. How can I re-size the video after it has started playing?

推荐答案

使用这个配置的变化

如果机器人:configchanges =方向

if android:configchanges = "orientation"

public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            // for example the width of a layout  
            int width = 300;
            int height = LayoutParams.WRAP_CONTENT;
            WebView childLayout = (WebView) findViewById(R.id.webview);
            childLayout.setLayoutParams(new LayoutParams(width, height));
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
        }
    }

这篇关于视频不重新调整大小时改变方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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