11

我正在使用 VerticalGridFragment 在类似网格的布局中显示项目我不需要显示搜索或标题,并且我希望行从屏幕顶部开始而没有任何边距。有什么帮助吗?下图中的示例

4

4 回答 4

12

我找到了一种方法,方法是覆盖VerticalGridFragmentVerticalGridPresenter ,然后获取VerticalGridView,并将顶部填充设置为较小的值。在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);
于 2016-08-24T05:50:27.817 回答
4

您需要创建名称为 CustomVerticalGridPresenter 的新类,并将后续代码放入其中

public class CustomVerticalGridPresenter extends VerticalGridPresenter {

    VerticalGridView gridView;

    CustomVerticalGridPresenter(int zoom, boolean val){
        super(zoom, val);
    }

    @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 videoGridPresenter = new 
CustomVerticalGridPresenter(ZOOM_FACTOR, false);

代替

VerticalGridPresentervideoGridPresenter = new VerticalGridPresenter(ZOOM_FACTOR, false);
于 2018-12-12T06:32:28.393 回答
3

解决此问题的另一种方法是设置 VerticalGridView 的 windowAlignment 属性。最为显着地 ...

verticalGridView.windowAlignment = BaseGridView.WINDOW_ALIGN_LOW_EDGE //this will remove the top margin
verticalGridView.windowAlignmentOffset = 0
verticalGridView.windowAlignmentOffsetPercent = 25f //find correct values for your case
于 2019-02-18T08:20:13.960 回答
1

First of follow this steps to move the rows up which is by default given margins by Lean back Library.

1. Go to you SDK.

2. Inside SDK -> extras -> android -> support -> v17 -> leanback -> res -> values.

3. Inside values folder copy the dimens.xml inside your current project and copy to your projects res -> values folder.

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

Now open the dimens.xml file which you have copied.

Change the value for property defined below. By default it will given 168dp around that. So make it less to decrease the top margin as i have given below.

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

现在,您可以在 Browse Fragment.

于 2016-08-19T07:16:10.253 回答