首页 > 解决方案 > 如何在 Exoplayer 的字幕视图中显示所需位置的文本

问题描述

我是安卓工作室的新手。我正在尝试自定义 exoplayer UI,并能够通过以下代码在我想要的位置显示播放器视图和播放控件。但字幕视图中的文本始终位于视口的底部。如何将字幕文本放置在所需位置,例如中心或字幕视图中的顶部?

我尝试过使用不同的xml布局,例如限制字幕视图的高度,但似乎字幕视图会占据播放器视图下方的所有空间。我还阅读了字幕视图类文档以找到实现所需的方法,但没有成功。提前感谢您的帮助。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<Button
android:id="@+id/Navigator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false" />

<com.google.android.exoplayer2.ui.AspectRatioFrameLayout 
    android:id="@id/exo_content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top|center">

    <!-- Video surface will be inserted as the first child of the content 
    frame. -->

    <View android:id="@id/exo_shutter"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"/>

    <View
        android:id="@id/exo_controller_placeholder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible" />

</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>

<com.google.android.exoplayer2.ui.SubtitleView 
    android:id="@id/exo_subtitles"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white" />

</LinearLayout>

这是模拟器上播放器的截图:

在此处输入图像描述

标签: javaxmlexoplayer

解决方案


推荐阅读