我具有被设置像这样的VideoView: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考虑它的控制器的高度?
谢谢。
你说的是WebView还是VideoView?你改变了一半。 –