Android 视频不适合视频视图纵向的宽度并且横向不占据全屏

2023-11-20

Android 视频在纵向时不适合视频视图的宽度,如何使视频的宽度在纵向时适合视频视图的宽度,当我将屏幕方向更改为横向时,我希望视频填充像 YouTube 应用程序一样全屏。当处于纵向时,视频将从屏幕的顶部到中间开始,而当处于横向时,视频将充满整个屏幕。这是我尝试过的,我还添加了完整的链接截屏

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

enter image description here


您需要有两种不同的布局。一张用于肖像,一张用于风景。 创建两个同名的 xml 文件,并将它们放入文件夹“layout-land”(横向)和“layout-port”(纵向)。

And Here 您可以看看如何处理方向变化。

这可以是使视频视图全屏的布局。

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

编辑:这是您在方法中处理它的方式。

@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);
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 视频不适合视频视图纵向的宽度并且横向不占据全屏 的相关文章

随机推荐

  • 为什么在 Laravel 5.8 中创建外键失败?

    下面的迁移脚本在旧版本的 Laravel 中运行顺利 但我将其添加到新的 Laravel 5 8 中并运行该脚本 我越来越Error foreign key was not formed correctly 评估迁移 public func
  • GWT Logger:无法控制调试输出?

    我的中有以下内容客户端 gwt xml file
  • Angular2 - 错误:无法解析 IconService 的所有参数

    我一直在尝试将我的应用程序切换到 AoT 编译 并且在加载应用程序时在生产环境中收到此错误 在本地运行良好 Error Can t resolve all parameters for IconService 似乎错误来自提供 IconSe
  • 如何:x86 中的 pow(real, real)

    我正在寻找实施pow real real 在 x86 程序集中 我也想了解该算法是如何工作的 只需将其计算为2 y log2 x 有一个 x86 指令 FYL2X 来计算 y log2 x 和一个 x86 指令 F2XM1 来进行求幂 F2
  • 没有 jquery 的 jquery 'trigger' 方法相当于什么?

    相当于什么jQuery s trigger方法无jQuery 例如 我该怎么做 blah trigger click 没有jQuery event initMouseEvent 点击 这是一个例子 function simulateClic
  • Delphi - 使用泛型的接口继承

    我目前遇到了编译错误 我们公司没有人可以提供帮助 遗憾的是我没有找到 SO 或 google 的正确搜索模式 作为代码 我使用 2 个继承的接口和 2 个继承的类 以下代码重现了该错误 program Project22 APPTYPE C
  • Lombok 的 lombok.copyableAnnotations 不适用于 Jackson 注释

    我正在尝试利用 Lombok 的新功能copyableAnnotations功能以便拥有 Jackson 注释 例如 JsonIgnore and JsonValue复制到生成的 getter wither 方法 该博客似乎表明这应该可行
  • Ajax 加载后如何执行 JavaScript?

    我需要在 ajax 加载后添加一个类 我首先给一些元素一个 ready 类 它启动 css 转换 当链接 li menu item 318 a 被点击时 它会删除就绪类 然后反转 css 转换 然后加载新的 html 文档 在 Aja 加载
  • Perl:如何在 X 秒后获取 IO::Socket::INET 超时?

    我正在尝试使用无效端口连接到某个主机 并且我希望在 X 秒后超时 怎么做 My code sock new IO Socket INET PeerAddr gt 0 PeerPort gt 1 Proto gt tcp Timeout gt
  • 按周数获取日期范围c# [重复]

    这个问题在这里已经有答案了 可能的重复 在 net中 知道周数如何获得工作日日期 Hello 我有一个问题要问你 如何获取给定周数的日期范围 例如 如果我进入第 12 周 输出应该是 21 03 2011 22 03 2011 23 03
  • 导入请求适用于 Windows shell,但不适用于 PyCharm

    简单导入请求 import requests 可以在 Windows shell 中执行和使用 但在 pycharm 中也有相同的代码 Traceback most recent call last File C Users XPS13 P
  • 有没有办法以编程方式生成 CouchDB cookie?

    我正在开发一个应用程序 它将使用 CouchDB 为用户存储一些数据 但我不希望用户直接登录CouchDB 我将有一个应用程序客户端 移动 网络 一个应用程序服务器和 CouchDB 服务器 客户端应用程序将向应用程序服务器进行身份验证 然
  • NullPointerException:使用 GSON 在 JAVA 中解析 JSON

    我想使用 Api GSON 通过 java 解析 JSON 文件以获取 JSON 文件的最后一个字段 描述符 json Teleservice 1 Record 1 method name mehdi method params param
  • 从 vim 中运行 PHP 文件

    是否可以在 vim 中运行 PHP 文件 我在这里尝试做的是有一个快捷方式 这样每当我需要运行我正在编辑的文件时 就可以跳过退出 vim 并手动调用 PHP 解释器 是的 做你想做的事是可能的 两者都从 vim 中运行 PHP 并创建快捷方
  • 跨域发布到 ASP.Net MVC 应用程序

    我正在开发一个应用程序 其中 HTML 和 javascript 块被传递到不同的客户端 我可以通过将以下内容添加到 Web 配置文件来获取 html javascript 块
  • JavaFX 使对象可见但不消耗(忽略)点击

    标题说明了一切 我在 JavaFX 中有一个矩形 用于透明 不透明效果 但我希望人们能够 点击 它 因此 当我说单击时 我的意思是当您单击它时 Java 应该假装它不存在 而是 单击 该对象下方的任何内容 当您使用 setVisible f
  • 与免费的 Java 分析器相比,商业 Java 分析器有哪些优势? Netbeans 中的那个?

    有时 我必须对 Java 代码进行一些分析工作 我想知道为什么我应该让我的老板使用商业分析器进行调查 而不是只使用 Netbeans 或 JConsole 中的分析器 值得投资的杀手级功能是什么 根据我使用 JProfiler 的经验 它是
  • 未捕获的类型错误:对象 [object Object] 没有方法“apply”

    我在我正在创建的新网站上收到此未捕获的类型错误 但我无法找出导致该错误的原因 我在下面的链接中重新创建了该问题 如果您查看浏览器的 JS 控制台 您会看到发生错误 但没有其他情况发生 http jsfiddle net EbR6D 2 Co
  • 有状态 lambda 表达式和无状态 lambda 表达式有什么区别?

    根据 OCP 一书 必须避免有状态操作 也称为有状态 lambda 表达式 书中提供的定义是 有状态 lambda 表达式是一种其结果取决于管道执行期间可能更改的任何状态的表达式 他们提供了一个示例 其中使用并行流将固定的数字集合添加到同步
  • Android 视频不适合视频视图纵向的宽度并且横向不占据全屏

    Android 视频在纵向时不适合视频视图的宽度 如何使视频的宽度在纵向时适合视频视图的宽度 当我将屏幕方向更改为横向时 我希望视频填充像 YouTube 应用程序一样全屏 当处于纵向时 视频将从屏幕的顶部到中间开始 而当处于横向时 视频将