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

Sas*_*ota 7 controls android exoplayer

我有自定义的ExoPlayer控制栏.它需要相当大的空间,我想让它变得更窄.

这是我要删除/缩小的内容(用红色突出显示):

在此输入图像描述

正如你看到的,我设法通过玩弄已经删除了一些空间paddingTop,layout_marginTop,layout_height参数(它使用的是更大).

但这还不够,还需要很大的空间.

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

这是我的自定义的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>
Run Code Online (Sandbox Code Playgroud)

注意:我完全理解通过缩小这些区域可能会使控制面板不太可用.没关系.我希望至少能够改变它们并测试它是如何工作的.

Ash*_*let 5

您应该做的第一件事是定义ImageButtonto的高度和宽度,以wrap_content使其正常运行。播放按钮上方的空白是由于缺少高度和宽度

现在最主要的。如果要删除TimeBar的填充,则需要设置app:touch_target_height此高度,以增加播放按钮和时间栏之间的填充。此高度是内部栏的触摸区域,您可以使用它来增加用户触摸区域,而无需增加栏的大小和这看起来像填充。使尺寸0dp和填充物消失

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

该播放按钮图片的大小为正方形,如您所见,播放按钮为三角形,因此他们添加了填充以使该图片位于中心和正方形。

附加:-您也可以使用定义内部钢筋的尺寸,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>
Run Code Online (Sandbox Code Playgroud)