【发布时间】:2019-08-22 15:28:14
【问题描述】:
我目前正在处理一些旧代码,这些代码以前在应用程序中用作弹出窗口,在某些文本旁边显示图像。我正在更改布局,将其从 ImageView 更改为 VideoView,以使其显示视频。我已将视频视图设置为仅跨越屏幕的某个部分,但视频并未停留在这些范围内。它按预期从这些边界的左上角开始,但跨越所有其他方向并越过屏幕的底部和右侧边缘。
旧代码在另一个带有重叠文本的 ImageView 旁边使用 ImageView 以构成弹出窗口。这些元素的父级是 PercentRelativeLayout。我尝试添加另一个相对布局,它是弹出窗口的总大小,然后在其中添加视频和图像视图(结构:百分比(全屏)-> 百分比(弹出窗口大小)-> 视频(父级的左半部分) & 图像(父母的右半边))。视频仍在扩展范围内。 我也尝试过使用约束布局而不是百分比布局,但它没有效果。 我在使用相同操作系统但硬件更快的不同设备上运行相同的代码,并且代码按预期工作。 除了设置视频源之外,我不会在代码中更改视频视图。
<android.support.percent.PercentFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
tools:context="com.my.package.questionnaire.fragments.InterestQuestionFragment">
<android.support.percent.PercentRelativeLayout
android:layout_gravity="center"
app:layout_aspectRatio="177%"
app:layout_widthPercent="100%">
<android.support.percent.PercentRelativeLayout
android:background="#000000"
app:layout_heightPercent="64%"
app:layout_marginStartPercent="13%"
app:layout_marginTopPercent="18%"
app:layout_widthPercent="74%">
<ImageView
android:src="@drawable/info_popup_background"
app:layout_heightPercent="100%"
app:layout_marginStartPercent="50%"
app:layout_widthPercent="50%" />
<VideoView
android:id="@+id/info_popup_accessory_video_view"
app:layout_heightPercent="100%"
app:layout_widthPercent="50%" />
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentFrameLayout>
预期结果是视频保持在 VideoView 的范围内。视频不大,应该已经与我正在创建的 VideoView 大小相同。它似乎被拉长了,但它不应该。
【问题讨论】:
标签: java android android-layout android-videoview