简体   繁体   English

从Android TV中的BrowseFragment中删除上边距

[英]Remove top margin from BrowseFragment in Android TV

How can I remove blank space, as shown in dotted box in below image from BrowseFragment . 如何删除空白区域,如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: 我尝试在我的AppTheme中设置以下内容,但我怀疑它有帮助:

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

在此输入图像描述

You can do this using it's dimens.xml which is provided in v17 Lean Back library. 您可以使用dimens.xml v17 Lean Back库中提供的dimens.xml来完成此操作。

Follow the steps below first.

  1. Go to your sdk -> extras -> android -> support -> v17 -> leanback -> res -> values . 转到您的sdk - > extras - > android - > support - > v17 - > leanback - > res - > values

  2. From their copy dimens.xml file into your current leanback project values folder. 从他们的复制dimens.xml文件到您当前的leanback项目values文件夹。

  3. Now you have the dimens.xml file inside your project values folder. 现在,您在项目values文件夹中有了dimens.xml文件。

  4. Open that file and find below dimen . 打开该文件,找到以下dimen

Default value may be 167dp given. 给定的默认值可能是167dp

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

So change it to around 30dp or as per your need. 因此,将其更改为大约30dp或根据您的需要。

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

You will get the rows up in Browse Fragment . 您将在Browse Fragment获取行。

If you need to remove the header margin in only the fragment instead of globally overwrite the BrowseFragment: 如果只需要删除片段中的标题边距而不是全局覆盖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;
}

the IanZ solution works perfectly. IanZ解决方案完美运行。 Other way to get the main container is FrameLayout containerDock = getView().findViewById(R.id.browse_container_dock); 获取主容器的其他方法是FrameLayout containerDock = getView().findViewById(R.id.browse_container_dock); in the main fragment without override oncreateView method. 在主片段中没有覆盖oncreateView方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM