Set fields between items in a BrowseFragment

Developing an application for Android TV, I ran into the problem of using BrowseFragment provided by the Leanback support library. Can we change the border between the RowsFragment elements?

+7
android android tv
source share
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 required field.

+5
source share

enter image description here

I found the answer myself. The key was a HorizontalGridView that stores a list of elements of all rows. We can get a link to this HorizontalGridView from R.id.row_content. Finally, the setItemMargin method was the solution for this. Below is a sample code and I can get the 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. ... }; 
+4
source share

Ideal to override style details, as @Billy replied. Unfortunately, it may take some time to figure out that. If what you are looking for is not stylish, you can apparently override the built-in shortage 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> 
0
source share

All Articles