VideoView to match parent height and keep aspect ratio

前端 未结 12 1918
轻奢々
轻奢々 2020-11-28 08:15

I have a VideoView which is set up like this:



        
12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 08:33

    Using ConstraintLayout we can achieve this, refer below xml code.

    When layout_width and layout_height are 0dp, the size and position of the VideoView are calculated dynamically based on the other constraints. The layout_constraintDimensionRatio attribute indicates that when the app calculates the size of the VideoView, the ratio of the width to the height should be 3:4. This constraint keeps the aspect ratio of the video the same and prevents the view from being stretched too far in either direction (depending on how the device is rotated).

    Change layout_constraintDimensionRatio value depending on requirement Portrait/Landscape.

    
    
        
    
    

提交回复
热议问题