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

问题描述 投票:6回答:1

我有自定义的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>

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

android controls exoplayer
1个回答
3
投票

你应该做的第一件事是将ImageButton的高度和宽度定义为wrap_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>

© www.soinside.com 2019 - 2024. All rights reserved.