Louis Nguyen
Louis Nguyen

Reputation: 345

Set position for Playback control of Android TV

I have problem with Android TV and I need your help.

Below is layout code:

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

And layout rendered:

enter image description here

How can I set position for Playback control of Android TV (etc: bottom, top...)?

Upvotes: 2

Views: 1233

Answers (3)

dell116
dell116

Reputation: 5905

After updating to API v28 / leanback support v28.x.x I found the answer provided by Louis Nguyen to no longer be working.

Looking at the PlaybackSupportFragment.setVerticalGridViewLayout() source code for API 28 / Leanback support 28.x.x, one can see Google changed how this alignment is being set.

TLDR

If you're using API v28 / Leanback support v28.x.x :

  • override the dimen value "lb_playback_other_rows_center_to_bottom"
  • A value of 135dp positions the playback controls to a position similar of that when we were using API v26 / LeanbackSupport v26.

If you're using API v26 / Leanback support v26.x.x

  • override the dimen value "lb_playback_controls_padding_top"
  • A value of 300dp keeps the controls at a place around the bottom with some good bottom margin

Upvotes: 1

mndivya
mndivya

Reputation: 3

change the ViewGroup from to

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

and add two xml attributes layout_alignParentBottom and layout_centerHorizontal to fragment as shown above.

It aligns playback_control_fragment bottom edge of this view match the bottom edge of the parent and centers this child horizontally within its parent.

https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

Upvotes: 0

Louis Nguyen
Louis Nguyen

Reputation: 345

I manual override padding dimen of Playback control (include top and bottom) with lb_playback_controls_padding_top and lb_playback_controls_padding_bottom

Upvotes: 0

Related Questions