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

时间:2018-09-02 16:11:00

标签: android controls exoplayer

我有自定义的ExoPlayer控制栏。这需要占用很多空间,我想缩小一点。

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

enter image description here

如您所见,我通过使用paddingToplayout_marginToplayout_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>

注意:我完全理解,通过缩小这些区域,可能会使控制面板的可用性降低。没关系。我至少希望能够更改它们并测试其工作方式。

1 个答案:

答案 0 :(得分:3)

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

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

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

此播放按钮图像的大小为正方形,并且您可以看到播放按钮为三角形,因此他们添加了填充以使该图像位于中心和正方形。

其他:-,您还可以使用app:bar_height定义内部钢筋的大小,但请记住app:bar_height不能越过app:touch_target_height。即使您定义的范围比app:touch_target_height多,您也看不到任何效果。您可以增加这些大小,并自己查看以下内容,这是我得到的最终结果(还编辑并删除了图像填充)。触摸条的按钮(按钮背景为空,时间条背景为#9e0c26

here

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

相关问题