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?
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.
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.
...
};
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With