2013-04-24 77 views
10

我試圖拉伸視頻以填充視頻視圖。目標是創建視圖,在設備中看起來像第一張圖片(就像它在佈局預覽中看到的一樣)。拉伸填充VideoView,縱橫比VideoView

這個問題的大部分答案都是指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> 

這裏有我的聲明佈局的預覽:

enter image description here

然而,在設備上的結果是不同的:

enter image description here

+0

您的佈局代碼可以滿足您的需求。但請記住,VideoView將相對於其中播放的視頻縮小/伸展。 – 2013-04-24 12:11:46

+0

好的,所以我需要改變媒體記錄器的寬高比來表示增加mMediaRecorder.setVideoSize(640,480);我嘗試這個,它不工作...? – idan 2013-04-24 12:27:34

+0

檢查這個答案http://stackoverflow.com/a/38971707/1153703 – 2016-08-16 09:52:15

回答

25

試着讓你的外部佈局成爲一個相對的佈局,並把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> 
+0

完美....謝謝.... – idan 2013-04-28 07:01:35

+0

偉大..它的工作.. – Neela 2015-10-22 18:02:42

+0

它fuc..ing workssss!這是實現這件事最簡單的方法。我一直在浪費很多時間來實現這一目標。非常感謝!!!!!! – KinGPinG 2017-03-07 15:07:21