2013-04-24 3 views
10

Я пытаюсь растянуть видео, чтобы заполнить видео. Цель состоит в том, чтобы создать представление, которое в устройстве выглядит как первый рис. (Как и в предварительном просмотре макета).Растянуть, чтобы заполнить 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» будет уменьшаться/растягиваться относительно воспроизведения видео в нем. –

+0

ok, поэтому мне нужно изменить соотношение сторон медиа-рекордера, чтобы добавить mMediaRecorder.setVideoSize (640, 480); Я пробую это, и он работает ... ??? – idan

+0

проверить этот ответ http://stackoverflow.com/a/38971707/1153703 –

ответ

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

+0

Great .. это работает .. – Neela

+0

It fuc..ing workssss !! Это самый простой способ достичь этой цели. Я тратил много времени на то, чтобы добиться этого. Большое спасибо!!!!!! – KinGPinG