Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set margins between items on BrowseFragment

Developing an application for Android TV, I faced a problem for the usage of BrowseFragment provided by Leanback support library. Can we change the margin between items of RowsFragment?

like image 404
corochann Avatar asked Sep 04 '15 16:09

corochann


3 Answers

You can override some styles to achieve this, for example:

<style name="AppTheme.Leanback" parent="Theme.Leanback">
  ..
  <item name="rowHorizontalGridStyle">@style/TvHorizontalGridView</item>
  ..
</style>

<style name="TvHorizontalGridView" parent="Widget.Leanback.Row.HorizontalGridView">
    <item name="horizontalMargin">@dimen/margin_medium</item>
    <item name="verticalMargin">@dimen/margin_medium</item>
</style>

where @dimen/margin_medium is the size of the margin that you want.

like image 69
Billy Avatar answered Nov 06 '22 08:11

Billy


enter image description here

I found the answer by myself. The key was HorizontalGridView which stores the each rows item list. We can get the reference of this HorizontalGridView by R.id.row_content. Finally, setItemMargin method was the solution for this. Below is a sample code, and I could get top image.

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    HorizontalGridView horizontalGridView = (HorizontalGridView) parent.findViewById(R.id.row_content);
    horizontalGridView.setItemMargin(400); // You can set item margin here.

    ...

    };
like image 45
corochann Avatar answered Nov 06 '22 09:11

corochann


Ideally override the style details as @Billy answered. It can unfortunately take a while to figure out whats what. If what you are looking for is not styleable you can apparently override the built-in leanback resources (not sure if reliable/safe though). eg:

<dimen name="lb_browse_rows_margin_top">167dp</dimen>
<dimen name="lb_browse_item_vertical_spacing">8dp</dimen>
<dimen name="lb_browse_expanded_row_no_hovercard_bottom_padding">28dp</dimen>
like image 2
gfunk Avatar answered Nov 06 '22 08:11

gfunk