6

How can I remove blank space, as shown in dotted box in below image from BrowseFragment. I managed to remove search button and title. Although, I also want to remove blank space and move video row at top of screen.

Is there any way to do this?

I tried setting following in my AppTheme, but I doubt it helps:

    <item name="browseRowsMarginTop">0dp</item>
    <item name="browsePaddingTop">0dp</item>

enter image description here

Uniruddh
  • 4,427
  • 3
  • 52
  • 86
  • You can do this by modifying `leanback layouts` itself. – Jay Rathod Oct 28 '16 at 06:51
  • I had tried changing following: `FrameLayout topHeader = (FrameLayout) getView().findViewById(R.id.browse_headers_dock); topHeader.setVisibility(View.GONE);` But its not removing that space. can you suggest which layout I should look to edit? – Uniruddh Oct 28 '16 at 06:55
  • Check my answer and let me know if you face any issue. – Jay Rathod Oct 28 '16 at 07:12

3 Answers3

12

You can do this using it's dimens.xml which is provided in v17 Lean Back library.

Follow the steps below first.

  1. Go to your sdk -> extras -> android -> support -> v17 -> leanback -> res -> values.

  2. From their copy dimens.xml file into your current leanback project values folder.

  3. Now you have the dimens.xml file inside your project values folder.

  4. Open that file and find below dimen.

Default value may be 167dp given.

<dimen name="lb_browse_rows_margin_top">167dp</dimen>

So change it to around 30dp or as per your need.

<dimen name="lb_browse_rows_margin_top">30dp</dimen>

You will get the rows up in Browse Fragment.

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
  • Could you please add to the answer steps, how you found out that this name was exactly `lb_browse_rows_margin_top`? – deathangel908 Mar 22 '18 at 11:39
  • for easy lookup use => cmd + shift + f (global search on mac, look for windows) and then paste "lb_browse_rows_margin_top" to get the desired file suggestions. – Arpit J. Jan 13 '20 at 19:44
3

If you need to remove the header margin in only the fragment instead of globally overwrite the BrowseFragment:

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    FrameLayout containerDock = (FrameLayout) view.findViewById(R.id.browse_container_dock);
    FrameLayout.MarginLayoutParams params = (FrameLayout.MarginLayoutParams) containerDock.getLayoutParams();
    Resources resources = inflater.getContext().getResources();
    int newHeaderMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, resources.getDisplayMetrics());
    int offsetToZero = -resources.getDimensionPixelSize(R.dimen.lb_browse_rows_margin_top);
    params.topMargin = offsetToZero+newHeaderMargin;
    containerDock.setLayoutParams(params);
    return view;
}
IanZ
  • 31
  • 2
-1

the IanZ solution works perfectly. Other way to get the main container is FrameLayout containerDock = getView().findViewById(R.id.browse_container_dock); in the main fragment without override oncreateView method.

slfan
  • 8,950
  • 115
  • 65
  • 78
Armin
  • 11
  • 3