1

我正在尝试使用视频视图在 android 中播放视频,但视频并未完全拉伸以适合屏幕,而是视频视图正在拉伸,并且在屏幕两侧显示黑色空屏幕

我希望在不考虑任何纵横比的情况下对视频进行拉伸。

对此有任何帮助

谢谢和纳根德拉

xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >

    <VideoView android:id="@+id/myvideoview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" />

</RelativeLayout>

代码:

setContentView(R.layout.main);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
videoPlayer = (VideoView) findViewById(R.id.myvideoview);
String uri = "android.resource://" + getPackageName() + "/" + R.raw.video;

videoPlayer.setVideoURI(Uri.parse(uri)); 
videoPlayer.setMediaController(new MediaController(this));
videoPlayer.requestFocus();
videoPlayer.setVisibility(0);
videoPlayer.start();

这是我用来播放视频的代码

感谢您的回复

4

2 回答 2

2

您可以做的一个技巧是将VideoViewa 放入内部RelativeLayout并添加参数:

android:layout_alignParentRight="true" android:layout_alignParentLeft="true" 
android:layout_alignParentTop="true" android:layout_alignParentBottom="true"

这会将视频“拉伸”为全屏。如果视频AspectRatio足够好,您将获得非常好的结果

于 2013-11-02T18:24:32.157 回答
0

VideoView的xml中的layout_width和layout_height使用fill_parent:

<VideoView android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="@+id/VideoView"></VideoView>
于 2011-06-23T06:10:53.060 回答