Leanback VerticalGridFragment remove top spacing

后端 未结 4 1648
不知归路
不知归路 2021-02-20 09:46

I am using VerticalGridFragment to display items in a grid-like layout I don\'t need to show search or title and I want the rows to start from top of the screen without any marg

4条回答
  •  佛祖请我去吃肉
    2021-02-20 10:10

    I found a way to do it by overriding the VerticalGridPresenter of the VerticalGridFragment then getting the VerticalGridView, and setting top padding to a smaller value. In the CustomVerticalGridPresenter class (that extends VerticalGridPresenter), override this method:

    @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);
    }
    

    Then in the VerticalGridFragment, assign the new CustomVerticalGridPresenter as following:

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

提交回复
热议问题