Android视频不恰当的宽度在videoview的纵向和不占用全屏景观 [英] Android Video not fitting the width in portrait of the videoview and not occupying full screen in landscape

查看:847
本文介绍了Android视频不恰当的宽度在videoview的纵向和不占用全屏景观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的视频不恰当的videoview的宽度时,在肖像,怎样才能使我的影片的宽度适合人像的时候,我videoview的宽度,当我改变屏幕的方向为横向我想视频以充满整个屏幕,如YouTube应用程序一样。当在纵向的视频是从顶部开始到屏幕和中间并且当在横向以填充整个屏幕。以下是我已经尽力了,我也加入了完整的截图

Android video not fitting the width of the videoview when in portrait, how can i make the width of my video fit the width of my videoview when in portrait, and when i change orientation of the screen to landscape i would like the video to fill the whole screen like the youtube app does. when in portrait the video is to start from the top to the middle of the screen and and when in landscape to fill the whole screen. here is what i have tried, i have also add links of the complete screenshot

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:weightSum="100" >

<VideoView
    android:id="@+id/videoview"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_gravity="center"
    android:layout_weight="53" >
</VideoView>

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="7"
    android:background="@drawable/top_bar"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/settings"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingTop="5dp" >

        <ImageView
            android:id="@+id/set"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/settings" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/low_tab"
        android:layout_width="70dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingTop="5dp" >

        <ImageView
            android:id="@+id/low"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/low" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/high_tab"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingTop="5dp" >

        <ImageView
            android:id="@+id/high"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/high" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/audio_tab"
        android:layout_width="70dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingTop="5dp" >

        <ImageView
            android:id="@+id/audio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/audio" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/full_screen"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingTop="5dp" >

        <ImageView
            android:id="@+id/full"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/full" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/fresh"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingTop="5dp" >

        <ImageView
            android:id="@+id/refresh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/refresh" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="7"
    android:background="@drawable/comment_bar"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/liveblog_tab"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:background="@drawable/select"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingTop="5dp" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/live_blog" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/addcom_tab"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:background="@drawable/select"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingLeft="15dp"
        android:paddingTop="5dp" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/desc"
            android:src="@drawable/add_comment" />
    </LinearLayout>
</LinearLayout>

<FrameLayout
    android:id="@+id/frame"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="33" >

    <LinearLayout
        android:id="@+id/liveblog"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <WebView
            android:id="@+id/browser"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </WebView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/comments"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>
</FrameLayout>

</LinearLayout>

推荐答案

您需要有两个不同的布局。一个用于纵向和一个为景观。 创建两个XML文件具有相同的名称,并把它们放进文件夹布局土地的景观和布局端口的肖像。

You need to have two different layouts. One for the portrait and the one for the landscape. Create two xml files with the same name and put them into folders "layout-land" for landscape and "layout-port" for portrait.

这里你可以看看如何处理方向改变。

And Here you can take a look how to handle orientation changes.

这可能是布局使视频全屏查看。

This can be the layout to make video view full screen.

<?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" >
<VideoView android:id="@+id/myvideoview"
         android:layout_width="fill_parent"
         android:layout_alignParentRight="true"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:layout_alignParentBottom="true"
         android:layout_height="fill_parent">
  </VideoView>
</RelativeLayout>

编辑:这是你如何处理它的方法

EDIT : This is How you can handle it in the method.

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

  // Checks the orientation of the screen
  if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    setContentView(Your Landscape layout);
  } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
    Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    setContentView(Your portrait layout);
  }
}

这篇关于Android视频不恰当的宽度在videoview的纵向和不占用全屏景观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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