本文介绍了Leanback VerticalGridFragment删除顶部间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用VerticalGridFragment以类似网格的布局显示项目我不需要显示搜索或标题,并且我希望这些行从屏幕顶部开始,没有任何边距.有帮助吗?
I am using VerticalGridFragment to display items in a grid-like layoutI don't need to show search or title and I want the rows to start from top of the screen without any margins. Any help?
推荐答案
您需要创建名称为CustomVerticalGridPresenter的新类,并在其中添加关注代码.
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);
}
}
然后在verticalgridfragment类中使用
Then in verticalgridfragment class use
CustomVerticalGridPresenter videoGridPresenter = new
CustomVerticalGridPresenter(ZOOM_FACTOR, false);
代替
VerticalGridPresentervideoGridPresenter = new VerticalGridPresenter(ZOOM_FACTOR, false);
这篇关于Leanback VerticalGridFragment删除顶部间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!