[英]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.
Go to your sdk
-> extras
-> android
-> support
-> v17
-> leanback
-> res
-> values
. 转到您的
sdk
- > extras
- > android
- > support
- > v17
- > leanback
- > res
- > values
。
From their copy dimens.xml
file into your current leanback project values
folder. 从他们的复制
dimens.xml
文件到您当前的leanback项目values
文件夹。
Now you have the dimens.xml
file inside your project values
folder. 现在,您在项目
values
文件夹中有了dimens.xml
文件。
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.