如何解决Android Studio 使视频宽度相对于视频高度
我正在尝试将背景制作成视频,但要获得正确的外观,我需要将高度与 match_parent 相匹配,然后将宽度相对于高度进行缩放。有没有办法做到这一点?
到目前为止,我所做的唯一方法是手动设置宽度,但这意味着随着高度的变化,它在某些设备上看起来会被压扁或拉伸。
<VideoView
android:id="@+id/vv_menu_card_animation"
android:layout_width="1280dp"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent" />
解决方法
在 ConstrainLayout 中,您还可以通过 layout_constraintDimensionRatio 将小部件的一个维度定义为另一个维度的比率。您可以在此处阅读更多信息:ConstrainLayout: Ratio。
如果您想要宽度 = 高度,您可以将此行添加到您的 VideoView:
app:layout_constraintDimensionRatio="1:1" android:layout_width="0dp"
<VideoView
android:id="@+id/vv_menu_card_animation"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintDimensionRatio="1:1"
/>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。