设置 Android 电视播放控制的位置
Set position for Playback control of Android TV
我在使用 Android 电视时遇到问题,我需要你的帮助。
下面是布局代码:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
/>
<fragment
android:id="@+id/playback_controls_fragment"
android:name="com.sharewis.leonettv.PlaybackOverlayFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
并呈现布局:
如何设置 Android 电视播放控制的位置(等:底部、顶部...)?
我用 lb_playback_controls_padding_top 和 lb_playback_controls_padding_bottom[=14= 手动覆盖播放控件的填充尺寸(包括顶部和底部) ]
将 ViewGroup 从更改为
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
/>
<fragment
android:id="@+id/playback_controls_fragment"
android:name="com.sharewis.leonettv.PlaybackOverlayFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
并向片段添加两个 xml 属性 layout_alignParentBottom 和 layout_centerHorizontal,如上所示。
它将 playback_control_fragment 此视图的底部边缘与父视图的底部边缘对齐,并将此子视图在其父视图中水平居中。
https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
更新到 API v28 / leanback 支持后 v28.x.x 我发现 Louis Nguyen 提供的答案不再有效。
查看 API 28 / Leanback 支持 28.x.x 的 PlaybackSupportFragment.setVerticalGridViewLayout() 源代码,可以看到 Google 改变了对齐方式的设置方式。
TLDR
如果您使用 API v28 / Leanback 支持 v28.x.x :
- 覆盖维度值
"lb_playback_other_rows_center_to_bottom"
- 135dp 的值将播放控件定位到与我们使用 API v26 / LeanbackSupport v26 时相似的位置。
如果您使用 API v26 / Leanback 支持 v26.x.x
- 覆盖维度值
"lb_playback_controls_padding_top"
- 300dp 的值使控件保持在底部周围的位置,并具有良好的底部边距
我在使用 Android 电视时遇到问题,我需要你的帮助。
下面是布局代码:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
/>
<fragment
android:id="@+id/playback_controls_fragment"
android:name="com.sharewis.leonettv.PlaybackOverlayFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
并呈现布局:
如何设置 Android 电视播放控制的位置(等:底部、顶部...)?
我用 lb_playback_controls_padding_top 和 lb_playback_controls_padding_bottom[=14= 手动覆盖播放控件的填充尺寸(包括顶部和底部) ]
将 ViewGroup 从更改为
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
/>
<fragment
android:id="@+id/playback_controls_fragment"
android:name="com.sharewis.leonettv.PlaybackOverlayFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
并向片段添加两个 xml 属性 layout_alignParentBottom 和 layout_centerHorizontal,如上所示。
它将 playback_control_fragment 此视图的底部边缘与父视图的底部边缘对齐,并将此子视图在其父视图中水平居中。
https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
更新到 API v28 / leanback 支持后 v28.x.x 我发现 Louis Nguyen 提供的答案不再有效。
查看 API 28 / Leanback 支持 28.x.x 的 PlaybackSupportFragment.setVerticalGridViewLayout() 源代码,可以看到 Google 改变了对齐方式的设置方式。
TLDR
如果您使用 API v28 / Leanback 支持 v28.x.x :
- 覆盖维度值
"lb_playback_other_rows_center_to_bottom"
- 135dp 的值将播放控件定位到与我们使用 API v26 / LeanbackSupport v26 时相似的位置。
如果您使用 API v26 / Leanback 支持 v26.x.x
- 覆盖维度值
"lb_playback_controls_padding_top"
- 300dp 的值使控件保持在底部周围的位置,并具有良好的底部边距