ExoPlayer:删除播放按钮和时间线行之间的冗余空格

ExoPlayer: remove redundant spaces between playback buttons and timeline row

我有自定义的 ExoPlayer 控制栏。这需要很多 space,我想把它缩小一点。

这是我想要的remove/narrower(用红色突出显示):

如您所见,我已经通过使用 paddingToplayout_marginToplayout_height 参数(它曾经更大)设法删除了一些 spaces .

但是还不够,还需要很多space.

问题:如何缩小图片上标记的空白区域?

这是我的自定义 exo_player_control_view.xml 的样子(为简单起见删除了大部分元素):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#CC000000"
    android:layoutDirection="ltr"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">
        <ImageButton
            android:id="@id/exo_play"
            style="@style/ExoMediaButton.Play" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal">
        <com.google.android.exoplayer2.ui.DefaultTimeBar
            android:id="@id/exo_progress"
            android:layout_width="0dp"
            android:layout_height="18dp"
            android:layout_weight="1" />
    </LinearLayout>

</LinearLayout>

注意:我完全理解缩小这些区域可能会降低控制面板的可用性。没关系。我希望至少有能力改变它们并测试它是如何工作的。

您应该做的第一件事是定义 ImageButtonwrap_content 的高度和宽度,以便它可以正常运行。 播放按钮上方的填充是由于缺少高度和宽度

现在是主要的事情。如果你想删除 TimeBar 的填充你需要设置 app:touch_target_height 这个高度增加你的播放按钮和时间之间的填充 bar.This 高度是内部条的触摸区域,你可以用它来增加用户在不增加条形大小的情况下触摸区域,这看起来像填充。使大小 0dp 并且填充将消失

好吧,还有一个填充是图像填充..我从 exoPlayer 库中提取了这个播放按钮图像,我发现这个图像也有一些默认填充。如果您还想删除该填充,请更改此图像。

这个播放按钮图片的大小是方形的,正如你所看到的,播放按钮是一个三角形,所以他们添加了填充来使这个图片居中并且是方形的。

Extra:- 您还可以使用 app:bar_height 定义内柱的大小,但请记住 app:bar_height 不能跨越 app:touch_target_height。即使你定义的比 app:touch_target_height 多,你也看不到任何效果。您可以增加这些尺寸并自己查看更多,下面是我得到的最终结果(还编辑并删除了图像填充)。触摸栏的按钮(按钮背景为空时间栏背景为#9e0c26

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#CC000000"
    android:layoutDirection="ltr"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageButton
            android:id="@id/exo_play"
            style="@style/ExoMediaButton.Play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <com.google.android.exoplayer2.ui.DefaultTimeBar
            android:id="@id/exo_progress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:bar_height="2dp"
            app:touch_target_height="2dp" />
    </LinearLayout>

</LinearLayout>