Using a VideoView is it possible to set a scale factor for Android? By Default the video view resizes itself to fit the encoded resolution of the Video. Can I force Android to render a video into a smaller or larger rect?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
To set
"centerCrop"
scale type forVideoView
youronMeasure()
andlayout()
methods may look like this:I am also trying to achieve that and so far this has worked ok. The idea is to use the setLayoutParams for the video view and specify the size. It is just a simple fragment but it gives the idea. Check the LayoutParams lines.
I find that when a VideoView is placed inside a RelativeLayout, the video stretches both height and width to fit the VideoView's specified height and width (irrespective of the video aspect ratio). However, when I place the VideoView in a FrameLayout, the video stretches height and width until it matches one of the VideoView's specified height or width (i.e. it does not break aspect ratio). Strange, I know, but that's what I found!
To FeelGoods answer.
Without the layout() method the "centerCrop" scale type is better, but the VideoView must be in a FrameLayout.
VideoView
(or theSurfaceView
for use withMediaPlayer
) will be the size you tell it to be in your layout. Within that space, the video will play back as large as possible while maintaining the aspect ratio.Yes: make your
VideoView
be the size you want, and Android will scale to fit the size of theVideoView
.(I know it's very old question, but there is another way to control dimensions, which isn't described here, maybe someone will find it helpful.)
Declare your own MyVideoView class in your layout and write your own onMeasure() method. Here is how to run video stretched to original View's dimensions: