LoginSignup
2
1

More than 1 year has passed since last update.

AndroidTV LeanbackのListRowPresenterのデフォルトpadding

Posted at

はじめに

AndroidTV開発で欠かせないLeanbackライブラリでUIを構築するときに、デフォルトでpaddingが設定されていることにより、うまく余白をコントロールできないことがありました。
今回はListRowPresenterのデフォルトpaddingのメモです。

本題

厳密には、ListRowPresenterのpaddingというよりは、ListRowPresenterが保持する ListRowView のレイアウトにスタイルが適用されています。

ListRowView
public final class ListRowView extends LinearLayout {
    public ListRowView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.lb_list_row, this);
        ...
    }
}

以下が R.layout.lb_list_row の中身です。
HorizontalGridViewに rowHorizontalGridStyle を適用しています。

R.layout.lb_list_row
...
<androidx.leanback.widget.HorizontalGridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:lb="http://schemas.android.com/apk/res-auto"
    android:id="@+id/row_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    lb:rowHeight="wrap_content"
    style="?attr/rowHorizontalGridStyle"  <-- これ />

遡っていくと、以下のpaddingが設定されていました。

values
    <style name="Widget.Leanback.Row.HorizontalGridView">
        <item name="android:focusable">true</item>
        <item name="android:focusableInTouchMode">true</item>
        <item name="android:paddingStart">?attr/browsePaddingStart</item>
        <item name="android:paddingEnd">?attr/browsePaddingEnd</item>
        <item name="android:paddingBottom">@dimen/lb_browse_item_vertical_spacing</item>
        <item name="android:paddingTop">@dimen/lb_browse_item_vertical_spacing</item>
        <item name="android:horizontalSpacing">@dimen/lb_browse_item_horizontal_spacing</item>
        <item name="android:verticalSpacing">@dimen/lb_browse_item_vertical_spacing</item>
        <item name="focusOutFront">true</item>
    </style>
dimens
    <dimen name="lb_browse_padding_end">56dp</dimen>
    <dimen name="lb_browse_padding_start">56dp</dimen>
    <dimen name="lb_browse_item_horizontal_spacing">8dp</dimen>
    <dimen name="lb_browse_item_vertical_spacing">8dp</dimen>

結論

デフォルトで

  • vertical方向に8dp
  • horizontal方向に56dp
  • grid間隔はどちらも8dp

ずつpaddingが設けられていました。

これを知っていると、カスタムでレイアウトを組みたい時に色々調整できそうです。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1