3

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"
        >

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.

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?

4

1 回答 1

2

使用此配置更改

如果 android:configchanges = "方向"

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();
        }
    }
于 2013-09-13T04:43:40.430 回答