【问题标题】:Stretch to fill VideoView, aspect ratio of VideoView拉伸以填充 VideoView,VideoView 的纵横比
【发布时间】:2013-04-17 23:04:04
【问题描述】:

我尝试拉伸视频以填充视频视图。目标是创建在设备中看起来像第一张图片的视图(就像它在布局预览中的样子)。

这个问题的大部分答案都参考this link

我试过了,但我仍然没有填满视频视图。

这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/search_gren_screen">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/go_back"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:onClick="onclick"
            android:text="Try again" />

        <Button
            android:id="@+id/back_to_pick_song"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Select another song" 
            android:onClick="onclick" />

        <Button
            android:id="@+id/btn_continue"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:onClick="onclick"
            android:text="Amazing, continue!" />
    </LinearLayout>

    <FrameLayout 
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    <VideoView 
        android:id="@+id/videoView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_gravity="center" />
    </FrameLayout>
</LinearLayout>

在这里您可以预览我声明的布局:

但是,设备上的结果不同:

【问题讨论】:

  • 您的布局代码可以满足您的需求。但请记住,VideoView 会相对于其中播放的视频进行收缩/拉伸。
  • 好的,所以我需要更改媒体记录器的纵横比意味着添加 mMediaRecorder.setVideoSize(640, 480);我试试这个,它不起作用...... ???

标签: android android-videoview aspect-ratio


【解决方案1】:

尝试使您的外部布局成为相对布局,并将 VideoView 放入其中。

类似:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/trim_container"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >

     <LinearLayout
          android:id="@+id/buttonContainer"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal" >

     <Button
          android:id="@+id/go_back"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="center"  
          android:layout_weight="1"
          android:onClick="onclick"
          android:text="Try again" />

     <Button
          android:id="@+id/back_to_pick_song"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1"
          android:text="Select another song" 
          android:onClick="onclick" />

    <Button
          android:id="@+id/btn_continue"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:layout_weight="1"
          android:onClick="onclick"
          android:text="Amazing, continue!" />
  </LinearLayout>

  <VideoView
     android:id="@+id/VideoView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
     android:layout_alignParentBottom="true"
     android:layout_below="@id/buttonContainer"/>
</RelativeLayout>

【讨论】:

  • 这该死的..好样的!!这是实现这一目标的最简单方法。我一直在浪费很多时间来尝试实现这一目标。非常感谢!!!!!!
【解决方案2】:

视频视图应该在相对布局的内部。这是下面给出的示例。就我而言,它与全屏按钮一起工作得很好。

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3"
            android:id="@+id/videoVIewLinId"
            android:layout_gravity="center"
            android:gravity="center"
            android:scaleType="fitXY"

            >
                <VideoView
                    android:layout_alignParentTop="true"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentStart="true"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/videoViewId"
                    />


                <ImageView
                    android:id="@+id/fullScreenBtnIdOnlineMedia"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_action_full_screen"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentBottom="true"
                    android:layout_marginEnd="10dp"

                    />

        </RelativeLayout>

【讨论】:

    【解决方案3】:

    fill_parent 方法对我不起作用。

    终于用上了这个库,效果很好!

    https://github.com/dmytrodanylyk/video-crop

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多