VideoView 裁剪为正方形
使用 ImageView
,我可以设置正方形的高度和宽度(例如 100dip x 100dip)。然后使用 android:scaleType="centerCrop" 给我一个被裁剪为正方形的图像,无论宽高比如何。
我们可以使用 VideoView
来做到这一点吗?
我尝试过仅设置正方形的高度和宽度,但它只是重新调整大小以尽可能地填充正方形,同时保持纵横比,我想这完全是预期的。
与 ImageView 不同,它似乎没有任何缩放或裁剪属性/方法,但是 VideoView 文档中的这一点让我觉得我错过了一些东西:
[VideoView] ...提供各种显示选项 例如缩放和着色。
任何想法将不胜感激。
Using an ImageView
, I can set a square height and width (say 100dip x 100dip). Then using android:scaleType="centerCrop"
gives me an image which is cropped to square regardless of aspect ratio.
Can we do this with a VideoView
?
I've tried just setting a square height and width, but it just re-sizes to fill the square as best as it can while maintaining the aspect ratio, which I guess is completely expected.
It doesn't seem to have any scale or crop properties / methods unlike ImageView
, but this in the VideoView
documentation makes me think I'm missing something:
[VideoView] ...provides various display options
such as scaling and tinting.
Any ideas would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
TextureView
实现视频裁剪效果需要 Android API 14 和硬件加速。我在我的文章此处。您还可以使用我的
TextureVideoView
- 基于 android 的自定义视图TextureView
让您能够轻松播放和裁剪视频。 非常相似这与
ImageView#setScaleType
布局代码
希望这会对某人有所帮助!
You achive video crop effect using
TextureView
which require Android API 14 and hardware acceleration. I described it in my article here.You can also use my
TextureVideoView
- custom view based on androidTextureView
which gives you ability to easy play and crop video. This very similar toImageView#setScaleType
Layout
Code
Hope this will help someone!
来源意味着它不是VideoView 视图本身不支持。您可以复制源代码并使其正常工作。 :) 最有可能的方法是在第 255 行添加 else,修改 onMeasure 以防止其扩展以满足尺寸等。
编辑:
如果参考文档略有偏差或完全错误,请不要感到惊讶。
Source implies that it isn't natively supported in the VideoView view. You could copy the source and make it work though. :) Most likely by adding an else at line 255, modifying onMeasure to prevent it from expanding to meet the size, etc.
Edit:
Don't be surprised that the Reference documentation is slightly off or just plain wrong.