我有自定义的 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>
注意:我完全理解缩小这些区域可能会降低控制面板的可用性。没关系。我至少希望能够更改它们并测试其工作原理。
最佳答案
您应该做的第一件事是将 ImageButton
的高度和宽度定义为 wrap_content
,以便它可以正常运行。
播放按钮上面的padding是因为缺少高度和宽度
现在是主要的事情。如果你想删除 TimeBar 的填充,你需要设置 app:touch_target_height
这个高度增加你的播放按钮和时间栏之间的填充。这个高度是内部栏的触摸区域,你可以用它来在不增加条形大小的情况下增加用户触摸区域,这看起来像填充。使大小 0dp
并且填充将消失
还有一个填充是图像填充..我从 exoPlayer
库中提取了这个播放按钮图像,我发现这个图像也有一些默认填充。如果您还想删除该填充,请更改此图像。
这个播放按钮图片的大小是正方形的,正如你所看到的,播放按钮是一个三角形,所以他们添加了填充来使这个图片居中和正方形。
Extra:- 您还可以使用 app:bar_height
定义内部栏的大小,但请记住 app:bar_height
不能超过 应用程序: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>
关于android - ExoPlayer:删除播放按钮和时间线行之间的冗余空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52138796/