Как установить VideoView Background с изображением в Android? - PullRequest
3 голосов
/ 01 сентября 2011

Есть ли способ установить фон VideoView с изображением, чтобы при воспроизведении видео черная часть с обеих сторон (слева и справа) отображала изображение в качестве фона. Я пробовал, но видео не видно, оно показывает только фоновое изображение, хотя видео воспроизводится, его звук слышен.

Вот мой 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"
    android:id="@+id/main_layout">
    <LinearLayout android:layout_height="wrap_content"
        android:id="@+id/linearLayout1" android:layout_width="fill_parent"
        android:background="@drawable/header">
        <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Chapter-1"
            android:textColor="#FFFFFF" android:layout_marginLeft="170dp"
            android:layout_marginTop="15dp"></TextView>
    </LinearLayout>
    <VideoView android:id="@+id/videoView1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"></VideoView>
    <LinearLayout android:layout_alignParentTop="@+id/videoView1"
        android:layout_centerInParent="true" android:layout_height="wrap_content"
        android:id="@+id/linearLayout2" android:layout_width="fill_parent"
        android:gravity="right">
        <TextView android:id="@+id/overTitle" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text=" text"
            android:textColor="#FFFFFF"></TextView>
    </LinearLayout>

    <LinearLayout android:layout_alignParentTop="@+id/videoView1"
        android:background="@drawable/footer"
        android:layout_alignParentBottom="true" android:layout_height="wrap_content"
        android:id="@+id/linearLayout2" android:layout_width="fill_parent"
        android:gravity="center">
        <Button android:id="@+id/menu_btn" android:layout_below="@+id/videoView1"
            android:layout_width="wrap_content" android:text="Menu"
            android:textColor="#FFFFFF" android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/videoView1" android:layout_alignRight="@+id/videoView1"
            android:background="@drawable/menu"></Button>
        <Button android:id="@+id/button2" android:layout_below="@+id/videoView1"
            android:layout_width="wrap_content" android:text="High"
            android:textColor="#FFFFFF" android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/videoView1" android:layout_alignRight="@+id/videoView1"
            android:background="@drawable/menu"></Button>
        <Button android:id="@+id/button2" android:layout_below="@+id/videoView1"
            android:layout_width="wrap_content" android:text="CC"
            android:textColor="#FFFFFF" android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/videoView1" android:layout_alignRight="@+id/videoView1"
            android:background="@drawable/menu"></Button>
        <Button android:id="@+id/exit_btn" android:layout_below="@+id/videoView1"
            android:layout_width="wrap_content" android:text="Exit"
            android:textColor="#FFFFFF" android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/videoView1" android:layout_alignRight="@+id/videoView1"
            android:background="@drawable/menu"></Button>
    </LinearLayout>

</RelativeLayout>

1 Ответ

0 голосов
/ 01 сентября 2011

вы можете адаптировать размер вашего видео к размеру видеокадра.таким образом, у вас нет черных полос слева и справа.

если вы устанавливаете фоновое изображение, вы должны установить вид видео в верхней части модели слоя.в противном случае изображение покрывает ваше видео, и вы не можете видеть видео.

РЕДАКТИРОВАТЬ

, чтобы установить размер видео, которое вы должны объявить как объект вваш макет, а не как сам макет.

вот пример:

    <LinearLayout android:id="@+id/LinearLayout01"
        android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" ...>

        <VideoView android:id="@+id/VideoView" android:layout_width="50dp" android:layout_height="50dp" ...(here you can set further setting of the video view)></VideoView>
        <Button android:text= ...></Button>
        <Button android:text=...></Button>          
    </LinearLayout>
...