拉伸以填充VideoView,VideoView的长宽比 [英] Stretch to fill VideoView, aspect ratio of VideoView

查看:137
本文介绍了拉伸以填充VideoView,VideoView的长宽比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to stretch video in aim to fill videoview. The target is to create view that in device look like the first pic (like it look in layout preview).

有关此问题的大多数答案,请参见

Most of the answers to this questions refer to this link.

我尝试了此操作,但仍然没有填充视频视图.

I tried this but I still didn't fill video view.

这是我的布局代码:

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

这是我声明的布局的预览:

Here you have a preview of my declared layout:

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

However, the result on the device is different:

推荐答案

尝试使外部布局成为相对布局,然后将VideoView放在其中.

Try to make your outer layout a relative layout and put the VideoView inside that.

类似的东西:

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

这篇关于拉伸以填充VideoView,VideoView的长宽比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆