我有一个这样设置的 VideoView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/player"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="@+id/video"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_centerVertical="true" />
<ProgressBar
android:id="@+id/loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
但是VideoView匹配父容器的宽度,然后根据加载的影片的纵横比设置高度。
我想做相反的事情,我希望 VideoView 匹配父级的高度,同时保持纵横比不变,视频将被剪裁在两侧。
我设法拉伸 VideoView 以填充父级,但没有保留纵横比。
另一件事是,我将 MediaController 添加到 VideoView 中,如下所示:
MediaController controllers = new MediaController(this) {
@Override
public void hide() {
if (state != State.Hidden) {
this.show();
}
else {
super.hide();
}
}
};
controllers.setAnchorView(videoView);
videoView.setMediaController(controllers);
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
controllers.show();
}
});
这很好用,并且控制器始终保持打开状态,但是在计算放置视频的位置时没有考虑控制器的高度(因为它是垂直居中的)。
那么我的两个问题是:
- 如何使 VideoView 与父级的高度匹配但保持纵横比?
- 如何让 VideoView 考虑其控制器的高度?
谢谢。