fill after a screen orientation change

I'm an iOS developer porting an iOS app to Android, so bear with me.I have a VideoView that is acting as a "video background". Everything about it is working correctly - except for in portrait view and on orientation change (to portrait view). In the AndroidManifest file, I have my activity setup so that screen orientations do not trigger a layout refresh:

android:configChanges="orientation|screenSize"

This is working correctly; what isn't working correctly is the aspect ratio of the video being played in the VideoView. The video is skewed to fit within the portrait bounds instead of cropping out the left and right sides to maintain aspect ratio. How can I force the VideoView to "aspect-fill" the video in it's container? I should also mention that this VideoView is a subview of a ConstraintView. Here is the applicable XML:

<VideoView
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:id="@+id/videoView2"
    app:layout_constraintBottom_toBottomOf="@+id/imageView3"
    app:layout_constraintLeft_toLeftOf="@+id/imageView3"
    app:layout_constraintRight_toRightOf="@+id/imageView3"
    app:layout_constraintTop_toTopOf="@+id/imageView4"
    android:scaleType="centerCrop"
    android:adjustViewBounds="true"/>

You can check for the orientation programatically after the orientation change (through onConfigurationChanged() ) and set your videoView scale type accordingly to what you want.

public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
        // set video view configurations to what you want on landscape
    }else{
        // set video view configurations to what you want on portrait
    }
}

About scaling the video view, that's another issue. Check this answers for more info about it: https://stackoverflow.com/a/7225469/4244598

https://stackoverflow.com/a/12335916/4244598

http://blog.kasenlam.com/2012/02/android-how-to-stretch-video-to-fill.html

链接地址: http://www.djcxy.com/p/46500.html

上一篇: Android:从相机保存的Jpeg看起来已损坏

下一篇: 在屏幕方向更改后填充