Растянуть до заполнения VideoView, соотношение сторон VideoView

Я пытаюсь растянуть видео, чтобы заполнить видеопросмотр. Цель состоит в том, чтобы создать представление, которое на устройстве будет выглядеть как первое изображение (как оно выглядит в предварительном просмотре макета).

Большинство ответов на эти вопросы относятся к эта ссылка.

Я пробовал это, но я все еще не заполнил просмотр видео.

Это мой код макета:

<?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>

Здесь у вас есть предварительный просмотр моего заявленного макета:

введите здесь описание изображения

Однако результат на устройстве другой:

введите здесь описание изображения


person idan    schedule 24.04.2013    source источник
comment
Ваш код макета подходит для удовлетворения ваших потребностей. Но имейте в виду, что VideoView будет сжиматься/растягиваться по отношению к воспроизводимому в нем видео.   -  person Nirmal Raghavan    schedule 24.04.2013
comment
хорошо, поэтому мне нужно изменить соотношение сторон медиа-рекордера, чтобы добавить mMediaRecorder.setVideoSize(640, 480); я пробую это, и это не работает ... ???   -  person idan    schedule 24.04.2013
comment
проверьте этот ответ stackoverflow.com/a/38971707/1153703   -  person Bikesh M    schedule 16.08.2016


Ответы (3)


Попробуйте сделать внешний макет относительным макетом и поместите в него 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>
person Joris    schedule 24.04.2013
comment
Это чертовски работает!! Это самый простой способ добиться этого. Я тратил много времени, пытаясь добиться этого. Большое спасибо!!!!!! - person KinGPinG; 07.03.2017

просмотр видео должен быть внутри относительного макета. Вот пример, приведенный ниже. В моем случае он отлично работает с полноэкранной кнопкой.

<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>
person Md. Masum Billah    schedule 11.02.2020

Метод fill_parent у меня не работает.

Наконец-то я использую эту библиотеку, отлично работает!

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

person Amos    schedule 17.08.2020