Leanback VerticalGridFragment remove top spacing

后端 未结 4 1660
不知归路
不知归路 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 09:52

    You need create new class with name CustomVerticalGridPresenter and put followig code in it.

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

    Then in verticalgridfragment class use

    CustomVerticalGridPresenter videoGridPresenter = new 
    CustomVerticalGridPresenter(ZOOM_FACTOR, false);
    

    instead of

    VerticalGridPresentervideoGridPresenter = new VerticalGridPresenter(ZOOM_FACTOR, false);
    

提交回复
热议问题