gpt4 book ai didi

android - Leanback VerticalGridFragment 移除顶部间距

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:21 31 4
gpt4 key购买 nike

我正在使用 VerticalGridFragment 以类似网格的布局显示项目我不需要显示搜索或标题,我希望行从屏幕顶部开始,没有任何边距。有什么帮助吗? example in the image below

最佳答案

我找到了一种方法,方法是覆盖 VerticalGridFragmentVerticalGridPresenter,然后获取 VerticalGridView,并将顶部填充设置为较小的值(value)。在 CustomVerticalGridPresenter 类(扩展 VerticalGridPresenter)中,覆盖此方法:

@Override
protected void initializeGridViewHolder(ViewHolder vh) {
super.initializeGridViewHolder(vh);
gridView = vh.getGridView();
int top= 20;//this is the new value for top padding
int bottom = gridView.getPaddingBottom();
int right = gridView.getPaddingRight();
int left = gridView.getPaddingLeft();
gridView.setPadding(left,top,right,bottom);
}

然后在 VerticalGridFragment 中,如下分配新的 CustomVerticalGridPresenter:

 CustomVerticalGridPresenter gridPresenter = new CustomVerticalGridPresenter();
gridPresenter.setNumberOfColumns(NUM_COLUMNS);
setGridPresenter(gridPresenter);

关于android - Leanback VerticalGridFragment 移除顶部间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39014243/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com